ansible: add ansible scripts to configure .conf file on collectd nodes
[barometer.git] / baro_tests / config_server.py
index 6506091..f35f788 100644 (file)
@@ -31,7 +31,6 @@ APEX_IP = os.getenv("INSTALLER_IP").rstrip('\n')
 APEX_USER = 'root'
 APEX_USER_STACK = 'stack'
 APEX_PKEY = '/root/.ssh/id_rsa'
-PATH = os.path.dirname(os.path.realpath(__file__))
 
 
 class Node(object):
@@ -184,6 +183,8 @@ class ConfigServer(object):
             if compute_name == node.get_dict()['name']:
                 stdout = node.run_cmd(
                     'cat /etc/collectd/collectd.conf.d/{}.conf'.format(plugin))
+                if stdout is None:
+                    return default_interval
                 for line in stdout.split('\n'):
                     if 'Interval' in line:
                         return 1
@@ -205,6 +206,8 @@ class ConfigServer(object):
             if compute_name == node.get_dict()['name']:
                 stdout = node.run_cmd(
                     'cat /etc/collectd/collectd.conf.d/{}.conf' .format(plugin))
+                if stdout is None:
+                    return default_values
                 for line in stdout.split('\n'):
                     if 'Interfaces' in line:
                         return line.split(' ', 1)[1]
@@ -266,8 +269,13 @@ class ConfigServer(object):
                 stdout = node.run_cmd(
                     "source overcloudrc.v3;"
                     + "openstack catalog list | grep gnocchi")
-                if 'gnocchi' in stdout:
+                if stdout is None:
+                    return False
+                elif 'gnocchi' in stdout:
                     gnocchi_present = True
+                    return gnocchi_present
+                else:
+                    return False
         return gnocchi_present
 
     def is_aodh_running(self, controller):
@@ -284,8 +292,13 @@ class ConfigServer(object):
                 stdout = node.run_cmd(
                     "source overcloudrc.v3;"
                     + "openstack catalog list | grep aodh")
-                if 'aodh' in stdout:
+                if stdout is None:
+                    return False
+                elif 'aodh' in stdout:
                     aodh_present = True
+                    return aodh_present
+                else:
+                    return False
         return aodh_present
 
     def is_mcelog_installed(self, compute, package):
@@ -302,7 +315,7 @@ class ConfigServer(object):
         for node in nodes:
             if compute_name == node.get_dict()['name']:
                 stdout = node.run_cmd(
-                    'yum list installed | grep mcelog')
+                    'rpm -qa | grep mcelog')
                 if stdout is None:
                     return 0
                 elif 'mcelog' in stdout:
@@ -339,7 +352,7 @@ class ConfigServer(object):
                 aodh_conf = node.run_cmd('ls /etc/collectd/collectd.conf.d')
                 if 'aodh.conf' not in aodh_conf:
                     self.__logger.info(
-                        "AODH Plugin not included in compute node")
+                        "AODH Plugin not included in {}".format(compute_name))
                     return False
                 else:
                     self.__logger.info(
@@ -364,11 +377,13 @@ class ConfigServer(object):
             if compute_name == node.get_dict()['name']:
                 gnocchi_conf = node.run_cmd('ls /etc/collectd/collectd.conf.d')
                 if 'collectd-ceilometer-plugin.conf' not in gnocchi_conf:
-                    self.__logger.info("Gnocchi Plugin not included")
+                    self.__logger.info(
+                        "Gnocchi Plugin not included in node {}".format(
+                            compute_name))
                     return False
                 else:
                     self.__logger.info(
-                        "Gnochi plugin available in compute node {}" .format(
+                        "Gnocchi plugin available in compute node {}" .format(
                             compute_name))
                     return True
         return True
@@ -401,13 +416,13 @@ class ConfigServer(object):
 
         Return boolean value indicating whether function was successful.
         """
+        csv_file = os.path.dirname(os.path.realpath(__file__)) + '/csv.conf'
         plugins = sorted(plugins)
         compute_name = compute.get_name()
         nodes = get_apex_nodes()
         for node in nodes:
             if compute_name == node.get_dict()['name']:
-                node.put_file(
-                    'PATH/csv.conf', 'csv.conf')
+                node.put_file(csv_file, 'csv.conf')
                 node.run_cmd(
                     'sudo cp csv.conf '
                     + '/etc/collectd/collectd.conf.d/csv.conf')
@@ -473,12 +488,18 @@ class ConfigServer(object):
                     "source overcloudrc.v3;"
                     + "aodh alarm list | grep {0} | grep {1}"
                     .format(criteria_list, compute))
+                if stdout is None:
+                    self.__logger.info("aodh alarm list was empty")
+                    return False
                 for line in stdout.splitlines():
                     line = line.replace('|', "")
                     metric_id = line.split()[0]
                     stdout = node.run_cmd(
                         'source overcloudrc.v3; aodh alarm show {}' .format(
                             metric_id))
+                    if stdout is None:
+                        self.__logger.info("aodh alarm list was empty")
+                        return False
                     for line in stdout.splitlines()[3: -1]:
                         line = line.replace('|', "")
                         if line.split()[0] == 'timestamp':
@@ -489,6 +510,9 @@ class ConfigServer(object):
                     stdout = node.run_cmd(
                         "source overcloudrc.v3; aodh alarm show {}" .format(
                             metric_id))
+                    if stdout is None:
+                        self.__logger.info("aodh alarm list was empty")
+                        return False
                     for line in stdout.splitlines()[3:-1]:
                         line = line.replace('|', "")
                         if line.split()[0] == 'timestamp':
@@ -511,6 +535,7 @@ class ConfigServer(object):
         timestamps1 = {}
         timestamps2 = {}
         nodes = get_apex_nodes()
+        sleep_time = plugin_interval + 2
         for node in nodes:
             if node.is_controller():
                 self.__logger.info('Getting gnocchi metric list on {}' .format(
@@ -522,22 +547,31 @@ class ConfigServer(object):
                     "source overcloudrc.v3;"
                     + "gnocchi metric list | grep {0} | grep {1}"
                     .format(criteria_list, compute))
+                if stdout is None:
+                        self.__logger.info("gnocchi list was empty")
+                        return False
                 for line in stdout.splitlines():
                     line = line.replace('|', "")
                     metric_id = line.split()[0]
                     stdout = node.run_cmd(
                         'source overcloudrc.v3;gnocchi measures show {}'.format(
                             metric_id))
+                    if stdout is None:
+                        self.__logger.info("gnocchi list was empty")
+                        return False
                     for line in stdout.splitlines()[3: -1]:
                         if line[0] == '+':
                             pass
                         else:
                             timestamps1 = line.replace('|', "")
                             timestamps1 = timestamps1.split()[0]
-                    time.sleep(10)
+                    time.sleep(sleep_time)
                     stdout = node.run_cmd(
                         "source overcloudrc.v3;gnocchi measures show {}".format(
                             metric_id))
+                    if stdout is None:
+                        self.__logger.info("gnocchi measures was empty")
+                        return False
                     for line in stdout.splitlines()[3:-1]:
                         if line[0] == '+':
                             pass
@@ -545,11 +579,16 @@ class ConfigServer(object):
                             timestamps2 = line.replace('|', "")
                             timestamps2 = timestamps2.split()[0]
                     if timestamps1 == timestamps2:
-                        self.__logger.info("Data not updated after 12 seconds")
+                        self.__logger.info(
+                            "Plugin Interval is {}" .format(plugin_interval))
+                        self.__logger.info(
+                            "Data not updated after {} seconds".format(
+                                sleep_time))
                         return False
                     else:
                         self.__logger.info("PASS")
                         return True
+        return False
 
     def test_plugins_with_snmp(
             self, compute, plugin_interval, logger, plugin, snmp_mib_files=[],