3 # jose.lausuch@ericsson.com
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
16 from functest.utils.constants import CONST
17 import functest.utils.functest_utils as ft_utils
18 import functest.utils.openstack_clean as os_clean
19 import functest.utils.openstack_snapshot as os_snapshot
22 class CliOpenStack(object):
25 self.os_auth_url = CONST.__getattribute__('OS_AUTH_URL')
26 self.endpoint_ip = None
27 self.endpoint_port = None
28 self.openstack_creds = CONST.__getattribute__('openstack_creds')
29 self.snapshot_file = CONST.__getattribute__('openstack_snapshot_file')
31 self.endpoint_ip = self.os_auth_url.rsplit("/")[2].rsplit(":")[0]
32 self.endpoint_port = self.os_auth_url.rsplit("/")[2].rsplit(":")[1]
34 def ping_endpoint(self):
35 if self.os_auth_url is None:
36 click.echo("Source the OpenStack credentials first '. $creds'")
38 response = os.system("ping -c 1 " + self.endpoint_ip + ">/dev/null")
42 click.echo("Cannot talk to the endpoint %s\n" % self.endpoint_ip)
46 def show_credentials():
47 for key, value in os.environ.items():
48 if key.startswith('OS_'):
49 click.echo("{}={}".format(key, value))
53 ft_utils.execute_command("sh %s" % pkg_resources.resource_filename(
54 'functest', 'ci/check_os.sh'), verbose=False)
56 def snapshot_create(self):
58 if os.path.isfile(self.snapshot_file):
59 answer = raw_input("It seems there is already an OpenStack "
60 "snapshot. Do you want to overwrite it with "
61 "the current OpenStack status? [y|n]\n")
63 if answer.lower() in ["y", "yes"]:
65 elif answer.lower() in ["n", "no"]:
68 answer = raw_input("Invalid answer. Please type [y|n]\n")
70 click.echo("Generating Openstack snapshot...")
73 def snapshot_show(self):
74 if not os.path.isfile(self.snapshot_file):
75 click.echo("There is no OpenStack snapshot created. To create "
76 "one run the command "
77 "'functest openstack snapshot-create'")
79 with open(self.snapshot_file, 'r') as yaml_file:
85 if not os.path.isfile(self.snapshot_file):
86 click.echo("Not possible to clean OpenStack without a snapshot. "
87 "This could cause problems. "
88 "Run first the command "
89 "'functest openstack snapshot-create'")