HC Test: update ODL startup in hc2vpp jobs
[csit.git] / resources / libraries / python / honeycomb / HoneycombSetup.py
index a067b2f..aa6f26d 100644 (file)
@@ -13,6 +13,8 @@
 
 """Implementation of keywords for Honeycomb setup."""
 
+from json import loads
+
 from ipaddress import IPv6Address, AddressValueError
 
 from robot.api import logger
@@ -163,7 +165,11 @@ class HoneycombSetup(object):
                 except HTTPRequestError:
                     ssh = SSH()
                     ssh.connect(node)
-                    ssh.exec_command("tail -n 100 /var/log/syslog")
+                    ret_code, _, _ = ssh.exec_command_sudo(
+                        "tail -n 100 /var/log/syslog")
+                    if ret_code != 0:
+                        # It's probably Centos
+                        ssh.exec_command_sudo("tail -n 100 /var/log/messages")
                     raise
                 if status_code == HTTPCodes.OK:
                     logger.info("Honeycomb on node {0} is up and running".
@@ -251,7 +257,7 @@ class HoneycombSetup(object):
             replace = '\\"restconf-binding-address\\": \\"0.0.0.0\\",'
 
         argument = '"/{0}/c\\ {1}"'.format(find, replace)
-        path = "{0}/config/honeycomb.json".format(Const.REMOTE_HC_DIR)
+        path = "{0}/config/restconf.json".format(Const.REMOTE_HC_DIR)
         command = "sed -i {0} {1}".format(argument, path)
 
         ssh = SSH()
@@ -457,10 +463,11 @@ class HoneycombSetup(object):
         ssh = SSH()
         ssh.connect(node)
 
-        cmd = "cp -r {src}/*karaf_{odl_name}* {dst}".format(
-            src=src_path, odl_name=odl_name, dst=dst_path)
+        cmd = "sudo rm -rf {dst}/*karaf_{odl_name} && " \
+              "cp -r {src}/*karaf_{odl_name}* {dst}".format(
+                  src=src_path, odl_name=odl_name, dst=dst_path)
 
-        ret_code, _, _ = ssh.exec_command(cmd, timeout=60)
+        ret_code, _, _ = ssh.exec_command_sudo(cmd, timeout=120)
         if int(ret_code) != 0:
             raise HoneycombError(
                 "Failed to copy ODL client on node {0}".format(node["host"]))
@@ -508,11 +515,13 @@ class HoneycombSetup(object):
         ssh.connect(node)
 
         cmd = "{path}/*karaf*/bin/client -u karaf feature:install " \
-              "odl-restconf-all odl-netconf-connector-all".format(path=path)
+              "odl-restconf-all " \
+              "odl-netconf-connector-all " \
+              "odl-netconf-topology".format(path=path)
         for feature in features:
             cmd += " {0}".format(feature)
 
-        ret_code, _, _ = ssh.exec_command_sudo(cmd, timeout=120)
+        ret_code, _, _ = ssh.exec_command_sudo(cmd, timeout=250)
 
         if int(ret_code) != 0:
             raise HoneycombError("Feature install did not succeed.")
@@ -553,6 +562,34 @@ class HoneycombSetup(object):
                                  format(status_code))
         return True
 
+    @staticmethod
+    def check_odl_shutdown_state(node):
+        """Check the status of ODL client shutdown.
+
+        :param node: Honeycomb node.
+        :type node: dict
+        :returns: True when ODL is stopped.
+        :rtype: bool
+        :raises HoneycombError: When the response is not code 200: OK.
+        """
+
+        cmd = "pgrep -f karaf"
+        path = HcUtil.read_path_from_url_file(
+            "odl_client/odl_netconf_connector")
+
+        try:
+            HTTPRequest.get(node, path, timeout=10, enable_logging=False)
+            raise HoneycombError("ODL client is still running.")
+        except HTTPRequestError:
+            logger.debug("Connection refused, checking process state....")
+            ssh = SSH()
+            ssh.connect(node)
+            ret_code, _, _ = ssh.exec_command(cmd)
+            if ret_code == 0:
+                raise HoneycombError("ODL client is still running.")
+
+        return True
+
     @staticmethod
     def mount_honeycomb_on_odl(node):
         """Tell ODL client to mount Honeycomb instance over netconf.
@@ -566,14 +603,21 @@ class HoneycombSetup(object):
             "odl_client/odl_netconf_connector")
 
         url_file = "{0}/{1}".format(Const.RESOURCES_TPL_HC,
-                                    "odl_client/mount_honeycomb.xml")
+                                    "odl_client/mount_honeycomb.json")
 
         with open(url_file) as template:
             data = template.read()
 
+        data = loads(data)
+
         status_code, _ = HTTPRequest.post(
-            node, path, headers={"Content-Type": "application/xml"},
-            payload=data, timeout=10, enable_logging=False)
+            node,
+            path,
+            headers={"Content-Type": "application/json",
+                     "Accept": "text/plain"},
+            json=data,
+            timeout=10,
+            enable_logging=False)
 
         if status_code == HTTPCodes.OK:
             logger.info("ODL mount point configured successfully.")
@@ -625,8 +669,7 @@ class HoneycombSetup(object):
         cmd = "service vpp stop"
         ret_code, _, _ = ssh.exec_command_sudo(cmd, timeout=80)
         if int(ret_code) != 0:
-            raise RuntimeError("Could not stop VPP service on node {0}".format(
-                node['host']))
+            logger.debug("VPP service refused to shut down.")
 
 
 class HoneycombStartupConfig(object):
@@ -651,7 +694,7 @@ class HoneycombStartupConfig(object):
         done
         """
 
-        self.java_call = "{scheduler} {affinity} java {jit_mode} {params}"
+        self.java_call = "{scheduler} {affinity} java{jit_mode}{params}"
 
         self.scheduler = ""
         self.core_affinity = ""
@@ -683,8 +726,8 @@ class HoneycombStartupConfig(object):
         self.ssh.connect(node)
         cmd = "echo '{config}' > /tmp/honeycomb " \
               "&& chmod +x /tmp/honeycomb " \
-              "&& sudo mv -f /tmp/honeycomb /opt/honeycomb".format(
-                config=self.config)
+              "&& sudo mv -f /tmp/honeycomb /opt/honeycomb".\
+            format(config=self.config)
         self.ssh.exec_command(cmd)
 
     def set_cpu_scheduler(self, scheduler="FIFO"):
@@ -721,9 +764,9 @@ class HoneycombStartupConfig(object):
         :type jit_mode: str
         """
 
-        modes = {"client": "-client",  # Default
-                 "server": "-server",  # Higher performance but longer warmup
-                 "classic": "-classic"  # Disables JIT compiler
+        modes = {"client": " -client",  # Default
+                 "server": " -server",  # Higher performance but longer warmup
+                 "classic": " -classic"  # Disables JIT compiler
                 }
 
         self.jit_mode = modes[jit_mode]
@@ -760,3 +803,10 @@ class HoneycombStartupConfig(object):
         architectures."""
 
         self.params += " -XX:+UseNUMA -XX:+UseParallelGC"
+
+    def set_ssh_security_provider(self):
+        """Disables BouncyCastle for SSHD."""
+        # Workaround for issue described in:
+        # https://wiki.fd.io/view/Honeycomb/Releases/1609/Honeycomb_and_ODL
+
+        self.params += " -Dorg.apache.sshd.registerBouncyCastle=false"