Stop raising keystoneauth1 exceptions in odl unit tests
[functest-xtesting.git] / functest / cli / commands / cli_os.py
1 #!/usr/bin/env python
2 #
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
8
9 # pylint: disable=missing-docstring
10
11 import os
12
13 import click
14 from six.moves import urllib
15
16 from functest.ci import check_deployment
17 from functest.utils import constants
18
19
20 class OpenStack(object):
21
22     def __init__(self):
23         self.os_auth_url = os.environ['OS_AUTH_URL']
24         self.endpoint_ip = None
25         self.endpoint_port = None
26         self.openstack_creds = constants.ENV_FILE
27         if self.os_auth_url:
28             self.endpoint_ip = urllib.parse.urlparse(self.os_auth_url).hostname
29             self.endpoint_port = urllib.parse.urlparse(self.os_auth_url).port
30
31     def ping_endpoint(self):
32         if self.os_auth_url is None:
33             click.echo("Source the OpenStack credentials first")
34             exit(0)
35         response = os.system("ping -c 1 " + self.endpoint_ip + ">/dev/null")
36         if response == 0:
37             return 0
38         else:
39             click.echo("Cannot talk to the endpoint %s\n" % self.endpoint_ip)
40             exit(0)
41
42     @staticmethod
43     def show_credentials():
44         dic_credentials = {}
45         for key, value in os.environ.items():
46             if key.startswith('OS_'):
47                 dic_credentials.update({key: value})
48         return dic_credentials
49
50     def check(self):
51         self.ping_endpoint()
52         deployment = check_deployment.CheckDeployment()
53         deployment.check_all()
54
55
56 class CliOpenStack(OpenStack):
57
58     @staticmethod
59     def show_credentials():
60         dic_credentials = OpenStack.show_credentials()
61         for key, value in dic_credentials.items():
62             if key.startswith('OS_'):
63                 click.echo("{}={}".format(key, value))