Add a new adapter for containerized Compass installer 81/53781/4
authorYifei Xue <xueyifei@huawei.com>
Wed, 14 Mar 2018 11:16:29 +0000 (19:16 +0800)
committerYifei Xue <xueyifei@huawei.com>
Thu, 15 Mar 2018 08:23:56 +0000 (16:23 +0800)
JIRA: -

Compass installer has been containerized since OPNFV 5.0.
To enable SFC test cases in Functest for Compass installer,
a new adapter is needed to be compatible with both containerized
Compass installer and SFC test cases.

Change-Id: I4e1a9e5fcbec016a0c3fde77ace9c2cc677e3e4c
Signed-off-by: Yifei Xue <xueyifei@huawei.com>
modules/opnfv/deployment/compass/adapter_container.py [new file with mode: 0644]
modules/opnfv/deployment/factory.py

diff --git a/modules/opnfv/deployment/compass/adapter_container.py b/modules/opnfv/deployment/compass/adapter_container.py
new file mode 100644 (file)
index 0000000..1713fe2
--- /dev/null
@@ -0,0 +1,83 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2018 HUAWEI TECHNOLOGIES CO.,LTD 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
+
+from opnfv.deployment import manager
+from opnfv.utils import opnfv_logger as logger
+from opnfv.utils import ssh_utils
+
+import yaml
+import os
+
+logger = logger.Logger(__name__).getLogger()
+
+
+class ContainerizedCompassAdapter():
+
+    def __init__(self, installer_ip, installer_user, pkey_file):
+
+        self.installer = 'compass'
+        self.installer_ip = installer_ip
+        self.installer_user = installer_user
+        self.pkey_file = pkey_file
+        self.DST_PATH_UC = "/tmp/openstack_user_config.yml"
+        self.nodes = []
+        self.ROLES = {}
+
+        if pkey_file is not None and not os.path.isfile(pkey_file):
+            raise Exception(
+                'The private key file %s does not exist!' % pkey_file)
+
+    def _find_nodes(self, file):
+        nodes = file['compute_hosts']
+        for compute in nodes:
+            self.ROLES[compute] = 'compute'
+        controllers = file['haproxy_hosts']
+        for controller in controllers:
+            nodes[controller] = controllers[controller]
+            self.ROLES[controller] = 'controller'
+        return nodes
+
+    def _process_nodes(self, raw_nodes):
+        nodes = []
+
+        for node in raw_nodes:
+            name = node
+            ip = raw_nodes[node]['ip']
+            status = 'active'
+            id = None
+            if self.ROLES[node] == 'controller':
+                roles = 'controller'
+            elif self.ROLES[node] == 'compute':
+                roles = 'compute'
+            ssh_client = ssh_utils.get_ssh_client(hostname=ip,
+                                                  username=self.installer_user,
+                                                  pkey_file=self.pkey_file)
+            node = manager.Node(id, ip, name, status, roles, ssh_client)
+            nodes.append(node)
+
+        return nodes
+
+    def get_nodes(self, options=None):
+        try:
+            # if we have retrieved previously all the nodes, don't do it again
+            # This fails the first time when the constructor calls this method
+            # therefore the try/except
+            if len(self.nodes) > 0:
+                return self.nodes
+        except:
+            pass
+
+        with open(self.DST_PATH_UC, 'r') as stream:
+            try:
+                file = yaml.load(stream)
+                raw_nodes = self._find_nodes(file)
+            except yaml.YAMLError as exc:
+                logger.error(exc)
+        self.nodes = self._process_nodes(raw_nodes)
+        return self.nodes
index 2788e5e..1fd8d44 100644 (file)
@@ -9,7 +9,7 @@
 
 
 from opnfv.deployment.apex import adapter as apex_adapter
-from opnfv.deployment.compass import adapter as compass_adapter
+from opnfv.deployment.compass import adapter_container as compass_adapter
 from opnfv.deployment.fuel import adapter as fuel_adapter
 from opnfv.deployment.osa import adapter as osa_adapter
 from opnfv.deployment.daisy import adapter as daisy_adapter
@@ -44,10 +44,10 @@ class Factory(object):
                                             installer_user=installer_user,
                                             installer_pwd=installer_pwd)
         elif installer.lower() == "compass":
-            return compass_adapter.CompassAdapter(
+            return compass_adapter.ContainerizedCompassAdapter(
                 installer_ip=installer_ip,
                 installer_user=installer_user,
-                installer_pwd=installer_pwd)
+                pkey_file=pkey_file)
         elif installer.lower() == "osa":
             return osa_adapter.OSAAdapter(installer_ip=installer_ip,
                                           installer_user=installer_user,