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
15 import functest.utils.functest_utils as ft_utils
16 import functest.utils.openstack_clean as os_clean
17 import functest.utils.openstack_snapshot as os_snapshot
19 functest_yaml = ft_utils.get_functest_yaml()
21 FUNCTEST_CONF_DIR = functest_yaml.get("general").get(
22 "directories").get("dir_functest_conf")
23 RC_FILE = os.getenv('creds')
24 OS_SNAPSHOT_FILE = ft_utils.get_parameter_from_yaml(
25 "general.openstack.snapshot_file")
31 self.os_auth_url = os.getenv('OS_AUTH_URL')
32 self.endpoint_ip = None
33 self.endpoint_port = None
34 if self.os_auth_url is not None:
35 self.endpoint_ip = self.os_auth_url.rsplit("/")[2].rsplit(":")[0]
36 self.endpoint_port = self.os_auth_url.rsplit("/")[2].rsplit(":")[1]
38 def ping_endpoint(self):
39 if self.os_auth_url is None:
40 click.echo("Source the OpenStack credentials first '. $creds'")
42 response = os.system("ping -c 1 " + self.endpoint_ip + ">/dev/null")
46 click.echo("Cannot talk to the endpoint %s\n" % self.endpoint_ip)
49 def show_credentials(self):
51 ft_utils.execute_command(cmd, exit_on_error=False, verbose=False)
54 def fetch_credentials(self):
55 if os.path.isfile(RC_FILE):
56 answer = raw_input("It seems the RC file is already present. "
57 "Do you want to overwrite it? [y|n]\n")
59 if answer.lower() in ["y", "yes"]:
61 elif answer.lower() in ["n", "no"]:
64 answer = raw_input("Invalid answer. Please type [y|n]\n")
66 CI_INSTALLER_TYPE = os.getenv('INSTALLER_TYPE')
67 if CI_INSTALLER_TYPE is None:
68 click.echo("The environment variable 'INSTALLER_TYPE' is not"
69 "defined. Please export it")
70 CI_INSTALLER_IP = os.getenv('INSTALLER_IP')
71 if CI_INSTALLER_IP is None:
72 click.echo("The environment variable 'INSTALLER_IP' is not"
73 "defined. Please export it")
74 cmd = ("/home/opnfv/repos/releng/utils/fetch_os_creds.sh "
76 % (RC_FILE, CI_INSTALLER_TYPE, CI_INSTALLER_IP))
77 click.echo("Fetching credentials from installer node '%s' with IP=%s.."
78 % (CI_INSTALLER_TYPE, CI_INSTALLER_IP))
79 ft_utils.execute_command(cmd, verbose=False)
83 cmd = ft_utils.FUNCTEST_REPO + "/ci/check_os.sh"
84 ft_utils.execute_command(cmd, verbose=False)
86 def snapshot_create(self):
88 if os.path.isfile(OS_SNAPSHOT_FILE):
89 answer = raw_input("It seems there is already an OpenStack "
90 "snapshot. Do you want to overwrite it with "
91 "the current OpenStack status? [y|n]\n")
93 if answer.lower() in ["y", "yes"]:
95 elif answer.lower() in ["n", "no"]:
98 answer = raw_input("Invalid answer. Please type [y|n]\n")
100 click.echo("Generating Openstack snapshot...")
103 def snapshot_show(self):
104 if not os.path.isfile(OS_SNAPSHOT_FILE):
105 click.echo("There is no OpenStack snapshot created. To create "
106 "one run the command "
107 "'functest openstack snapshot-create'")
109 with open(OS_SNAPSHOT_FILE, 'r') as yaml_file:
115 if not os.path.isfile(OS_SNAPSHOT_FILE):
116 click.echo("Not possible to clean OpenStack without a snapshot. "
117 "This could cause problems. "
118 "Run first the command "
119 "'functest openstack snapshot-create'")