aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2016-08-22 12:51:22 +0200
committerCédric Ollivier <cedric.ollivier@orange.com>2016-08-22 12:54:38 +0200
commit0a40f5ecc5b2362e8b4dc2ec054daf611ac7f77e (patch)
tree07d85c584987d068c6230739e17ffcd5b9be7285
parent4fcf3d2079e505a6337abe1b850c7a7f6afddada (diff)
Add logs (info)
It adds logs (info) when status is ok and fixes an exception printing too. It removes one useless log (debug). Change-Id: Ia59c3985ae749b80d0e0c07f331220bd33cd8007 Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
-rwxr-xr-xtestcases/Controllers/ODL/OpenDaylightTesting.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/testcases/Controllers/ODL/OpenDaylightTesting.py b/testcases/Controllers/ODL/OpenDaylightTesting.py
index c9c658ee..2075d13a 100755
--- a/testcases/Controllers/ODL/OpenDaylightTesting.py
+++ b/testcases/Controllers/ODL/OpenDaylightTesting.py
@@ -68,7 +68,6 @@ class ODLTestCases:
def set_robotframework_vars(cls, odlusername="admin", odlpassword="admin"):
odl_variables_files = cls.odl_test_repo + 'csit/variables/Variables.py'
try:
- cls.logger.debug(cls.neutron_suite_dir + '__init__.robot')
for line in fileinput.input(odl_variables_files,
inplace=True):
print re.sub("AUTH = .*",
@@ -77,7 +76,7 @@ class ODLTestCases:
line.rstrip())
return True
except Exception as e:
- cls.logger.error("Cannot set ODL creds", e)
+ cls.logger.error("Cannot set ODL creds: %s" % e.strerror)
return False
@classmethod
@@ -113,6 +112,7 @@ class ODLTestCases:
stdout=stdout)
with open(stdout_file, 'r') as stdout:
cls.logger.info("\n" + stdout.read())
+ cls.logger.info("ODL results was sucessfully generated")
return True
else:
return False
@@ -134,6 +134,7 @@ class ODLTestCases:
cls.logger.error("Cannot push ODL results to DB")
return False
else:
+ cls.logger.info("ODL results was sucessfully pushed to DB")
return True
except RobotError as e:
cls.logger.error("Run tests before publishing: %s" % e.message)
n */ .highlight .nf { color: #a6e22e } /* Name.Function */ .highlight .nl { color: #f8f8f2 } /* Name.Label */ .highlight .nn { color: #f8f8f2 } /* Name.Namespace */ .highlight .nx { color: #a6e22e } /* Name.Other */ .highlight .py { color: #f8f8f2 } /* Name.Property */ .highlight .nt { color: #f92672 } /* Name.Tag */ .highlight .nv { color: #f8f8f2 } /* Name.Variable */ .highlight .ow { color: #f92672 } /* Operator.Word */ .highlight .w { color: #f8f8f2 } /* Text.Whitespace */ .highlight .mb { color: #ae81ff } /* Literal.Number.Bin */ .highlight .mf { color: #ae81ff } /* Literal.Number.Float */ .highlight .mh { color: #ae81ff } /* Literal.Number.Hex */ .highlight .mi { color: #ae81ff } /* Literal.Number.Integer */ .highlight .mo { color: #ae81ff } /* Literal.Number.Oct */ .highlight .sa { color: #e6db74 } /* Literal.String.Affix */ .highlight .sb { color: #e6db74 } /* Literal.String.Backtick */ .highlight .sc { color: #e6db74 } /* Literal.String.Char */ .highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */ .highlight .sd { color: #e6db74 } /* Literal.String.Doc */ .highlight .s2 { color: #e6db74 } /* Literal.String.Double */ .highlight .se { color: #ae81ff } /* Literal.String.Escape */ .highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */ .highlight .si { color: #e6db74 } /* Literal.String.Interpol */ .highlight .sx { color: #e6db74 } /* Literal.String.Other */ .highlight .sr { color: #e6db74 } /* Literal.String.Regex */ .highlight .s1 { color: #e6db74 } /* Literal.String.Single */ .highlight .ss { color: #e6db74 } /* Literal.String.Symbol */ .highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #a6e22e } /* Name.Function.Magic */ .highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */ .highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */ .highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */ .highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */ .highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */ } @media (prefers-color-scheme: light) { .highlight .hll { background-color: #ffffcc } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
#!/usr/bin/env python

# Copyright (c) 2017 Ericsson and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0

"""
OpenStack deployment checker

Verifies that:
 - Credentials file is given and contains the right information
 - OpenStack endpoints are reachable
"""

import logging
import logging.config
import os
import pkg_resources
import socket
from urlparse import urlparse

from snaps.openstack.utils import glance_utils
from snaps.openstack.utils import keystone_utils
from snaps.openstack.utils import neutron_utils
from snaps.openstack.utils import nova_utils
from snaps.openstack.tests import openstack_tests

__author__ = "Jose Lausuch <jose.lausuch@ericsson.com>"

LOGGER = logging.getLogger(__name__)


def verify_connectivity(adress, port):
    """ Returns true if an ip/port is reachable"""
    connection = socket.socket()
    connection.settimeout(10)
    try:
        connection.connect((adress, port))
        LOGGER.debug('%s:%s is reachable!', adress, port)
        return True
    except socket.error:
        LOGGER.error('%s:%s is not reachable.', adress, port)
    return False


class CheckDeployment(object):
    """ Check deployment class."""

    def __init__(self, rc_file='/home/opnfv/functest/conf/openstack.creds'):
        self.rc_file = rc_file
        self.services = ('compute', 'network', 'image')
        self.os_creds = None

    def check_rc(self):
        """ Check if RC file exists and contains OS_AUTH_URL """
        if not os.path.isfile(self.rc_file):
            raise IOError('RC file {} does not exist!'.format(self.rc_file))
        if 'OS_AUTH_URL' not in open(self.rc_file).read():
            raise SyntaxError('OS_AUTH_URL not defined in {}.'.
                              format(self.rc_file))

    def check_auth_endpoint(self):
        """ Verifies connectivity to the OS_AUTH_URL given in the RC file """
        rc_endpoint = self.os_creds.auth_url
        if not (verify_connectivity(urlparse(rc_endpoint).hostname,
                                    urlparse(rc_endpoint).port)):
            raise Exception("OS_AUTH_URL {} is not reachable.".
                            format(rc_endpoint))
        LOGGER.info("Connectivity to OS_AUTH_URL %s ...OK", rc_endpoint)

    def check_public_endpoint(self):
        """ Gets the public endpoint and verifies connectivity to it """
        public_endpoint = keystone_utils.get_endpoint(self.os_creds,
                                                      'identity',
                                                      interface='public')
        if not (verify_connectivity(urlparse(public_endpoint).hostname,
                                    urlparse(public_endpoint).port)):
            raise Exception("Public endpoint {} is not reachable.".
                            format(public_endpoint))
        LOGGER.info("Connectivity to the public endpoint %s ...OK",
                    public_endpoint)

    def check_service_endpoint(self, service):
        """ Verifies connectivity to a given openstack service """
        endpoint = keystone_utils.get_endpoint(self.os_creds,
                                               service,
                                               interface='public')
        if not (verify_connectivity(urlparse(endpoint).hostname,
                                    urlparse(endpoint).port)):
            raise Exception("{} endpoint {} is not reachable.".
                            format(service, endpoint))
        LOGGER.info("Connectivity to endpoint '%s' %s ...OK",
                    service, endpoint)

    def check_nova(self):
        """ checks that a simple nova operation works """
        try:
            client = nova_utils.nova_client(self.os_creds)
            client.servers.list()
            LOGGER.info("Nova service ...OK")
        except Exception as error:
            LOGGER.error("Nova service ...FAILED")
            raise error

    def check_neutron(self):
        """ checks that a simple neutron operation works """
        try:
            client = neutron_utils.neutron_client(self.os_creds)
            client.list_networks()
            LOGGER.info("Neutron service ...OK")
        except Exception as error:
            LOGGER.error("Neutron service ...FAILED")
            raise error

    def check_glance(self):
        """ checks that a simple glance operation works """
        try:
            client = glance_utils.glance_client(self.os_creds)
            client.images.list()
            LOGGER.info("Glance service ...OK")
        except Exception as error:
            LOGGER.error("Glance service ...FAILED")
            raise error

    def check_all(self):
        """
        Calls all the class functions and returns 0 if all of them succeed.
        This is the method called by prepare_env or CLI
        """
        self.check_rc()
        try:
            self.os_creds = openstack_tests.get_credentials(
                os_env_file=self.rc_file,
                proxy_settings_str=None,
                ssh_proxy_cmd=None)
        except:
            raise Exception("Problem while getting credentials object.")
        if self.os_creds is None:
            raise Exception("Credentials is None.")
        self.check_auth_endpoint()
        self.check_public_endpoint()
        for service in self.services:
            self.check_service_endpoint(service)
        self.check_nova()
        self.check_neutron()
        self.check_glance()
        return 0


def main():
    """Entry point"""
    logging.config.fileConfig(pkg_resources.resource_filename(
        'functest', 'ci/logging.ini'))
    logging.captureWarnings(True)
    deployment = CheckDeployment()
    return deployment.check_all()