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
21 ft_utils.get_functest_config('general.directories.dir_functest_conf')
22 RC_FILE = os.getenv('creds')
24 ft_utils.get_functest_config("general.openstack.snapshot_file")
30 self.os_auth_url = os.getenv('OS_AUTH_URL')
31 self.endpoint_ip = None
32 self.endpoint_port = None
33 if self.os_auth_url is not None:
34 self.endpoint_ip = self.os_auth_url.rsplit("/")[2].rsplit(":")[0]
35 self.endpoint_port = self.os_auth_url.rsplit("/")[2].rsplit(":")[1]
37 def ping_endpoint(self):
38 if self.os_auth_url is None:
39 click.echo("Source the OpenStack credentials first '. $creds'")
41 response = os.system("ping -c 1 " + self.endpoint_ip + ">/dev/null")
45 click.echo("Cannot talk to the endpoint %s\n" % self.endpoint_ip)
48 def show_credentials(self):
49 for key, value in os.environ.items():
50 if key.startswith('OS_'):
51 click.echo("{}={}".format(key, value))
53 def fetch_credentials(self):
54 if os.path.isfile(RC_FILE):
55 answer = raw_input("It seems the RC file is already present. "
56 "Do you want to overwrite it? [y|n]\n")
58 if answer.lower() in ["y", "yes"]:
60 elif answer.lower() in ["n", "no"]:
63 answer = raw_input("Invalid answer. Please type [y|n]\n")
65 CI_INSTALLER_TYPE = os.getenv('INSTALLER_TYPE')
66 if CI_INSTALLER_TYPE is None:
67 click.echo("The environment variable 'INSTALLER_TYPE' is not"
68 "defined. Please export it")
69 CI_INSTALLER_IP = os.getenv('INSTALLER_IP')
70 if CI_INSTALLER_IP is None:
71 click.echo("The environment variable 'INSTALLER_IP' is not"
72 "defined. Please export it")
73 cmd = ("/home/opnfv/repos/releng/utils/fetch_os_creds.sh "
75 % (RC_FILE, CI_INSTALLER_TYPE, CI_INSTALLER_IP))
76 click.echo("Fetching credentials from installer node '%s' with IP=%s.."
77 % (CI_INSTALLER_TYPE, CI_INSTALLER_IP))
78 ft_utils.execute_command(cmd, verbose=False)
82 cmd = ft_utils.FUNCTEST_REPO + "/ci/check_os.sh"
83 ft_utils.execute_command(cmd, verbose=False)
85 def snapshot_create(self):
87 if os.path.isfile(OS_SNAPSHOT_FILE):
88 answer = raw_input("It seems there is already an OpenStack "
89 "snapshot. Do you want to overwrite it with "
90 "the current OpenStack status? [y|n]\n")
92 if answer.lower() in ["y", "yes"]:
94 elif answer.lower() in ["n", "no"]:
97 answer = raw_input("Invalid answer. Please type [y|n]\n")
99 click.echo("Generating Openstack snapshot...")
102 def snapshot_show(self):
103 if not os.path.isfile(OS_SNAPSHOT_FILE):
104 click.echo("There is no OpenStack snapshot created. To create "
105 "one run the command "
106 "'functest openstack snapshot-create'")
108 with open(OS_SNAPSHOT_FILE, 'r') as yaml_file:
114 if not os.path.isfile(OS_SNAPSHOT_FILE):
115 click.echo("Not possible to clean OpenStack without a snapshot. "
116 "This could cause problems. "
117 "Run first the command "
118 "'functest openstack snapshot-create'")