Browse Source

New format of inputing data for DVS

Change-Id: I159cd3e024736890cc35fcf9cc9ee1bb3a7069e1
Vasily Gorin 2 years ago
parent
commit
c237dc0765
1 changed files with 48 additions and 28 deletions
  1. 48
    28
      plugin_test/helpers/plugin.py

+ 48
- 28
plugin_test/helpers/plugin.py View File

@@ -15,17 +15,17 @@ under the License.
15 15
 
16 16
 import os
17 17
 
18
-from fuelweb_test import logger
18
+from proboscis.asserts import assert_true
19 19
 
20
+from fuelweb_test import logger
20 21
 from fuelweb_test.helpers import utils
21 22
 
22
-from proboscis.asserts import assert_true
23
-
24 23
 # constants
25 24
 DVS_PLUGIN_PATH = os.environ.get('DVS_PLUGIN_PATH')
26 25
 DVS_PLUGIN_VERSION = os.environ.get('DVS_PLUGIN_VERSION')
27
-DVS_SWITCHES = os.environ.get('DVS_SWITCHES').split(',')
28
-VCENTER_CLUSTERS = os.environ.get('VCENTER_CLUSTERS').split(',')
26
+DVS_SWITCHES = os.environ.get('DVS_SWITCHES').strip().split(',')
27
+DVS_UPLINKS = os.environ.get('DVS_UPLINKS').strip().split(',')
28
+VCENTER_CLUSTERS = os.environ.get('VCENTER_CLUSTERS').strip().split(',')
29 29
 msg = "Plugin couldn't be enabled. Check plugin version. Test aborted"
30 30
 plugin_name = "fuel-plugin-vmware-dvs"
31 31
 
@@ -33,31 +33,51 @@ plugin_name = "fuel-plugin-vmware-dvs"
33 33
 def install_dvs_plugin(master_node):
34 34
     """Download and instal DVS plugin on master node."""
35 35
     # copy plugins to the master node
36
-    utils.upload_tarball(
37
-        master_node,
38
-        DVS_PLUGIN_PATH, "/var")
36
+    utils.upload_tarball(master_node, DVS_PLUGIN_PATH, "/var")
39 37
 
40 38
     # install plugin
41
-    utils.install_plugin_check_code(
42
-        master_node,
43
-        os.path.basename(DVS_PLUGIN_PATH))
44
-
45
-
46
-def enable_plugin(cluster_id, fuel_web_client, multiclusters=True):
47
-    """Enable DVS plugin on cluster."""
48
-    assert_true(
49
-        fuel_web_client.check_plugin_exists(
50
-            cluster_id, plugin_name),
51
-        msg)
52
-    map_switch_clusters = map(
53
-        lambda x, y: "{0}:{1}".format(x, y), VCENTER_CLUSTERS, DVS_SWITCHES)
54
-    if multiclusters is True:
55
-        options = {'vmware_dvs_net_maps/value': ';'.join(map_switch_clusters)}
56
-    else:
57
-        options = {'vmware_dvs_net_maps/value': map_switch_clusters[0]}
39
+    utils.install_plugin_check_code(master_node,
40
+                                    os.path.basename(DVS_PLUGIN_PATH))
58 41
 
42
+
43
+def enable_plugin(cluster_id, fuel_web_client, multiclusters=True, tu=0, fu=0):
44
+    """Enable DVS plugin on cluster.
45
+
46
+    :param cluster_id: cluster id
47
+    :param fuel_web_client: fuel_web
48
+    :param multiclusters: boolean. True if Multicluster is used.
49
+    :param tu: int, amount of teaming uplinks
50
+    :param fu: int, amount of falback uplinks
51
+    :return: None
52
+    """
53
+    checker = fuel_web_client.check_plugin_exists(cluster_id, plugin_name)
54
+    assert_true(checker, msg)
55
+    opts = {'vmware_dvs_net_maps/value': make_map_data(multiclusters, tu, fu)}
59 56
     logger.info("cluster is {0}".format(cluster_id))
57
+    fuel_web_client.update_plugin_settings(cluster_id, plugin_name,
58
+                                           DVS_PLUGIN_VERSION, opts)
59
+
60 60
 
61
-    fuel_web_client.update_plugin_settings(
62
-        cluster_id, plugin_name,
63
-        DVS_PLUGIN_VERSION, options)
61
+def make_map_data(multiclusters=False, tu=2, fu=1):
62
+    """ Make DVS mapping data to paste it to options
63
+
64
+    :param multiclusters: boolean. True if Multicluster is used.
65
+    :param tu: int, amount of teaming uplinks
66
+    :param fu: int, amount of falback uplinks
67
+    :return:
68
+    """
69
+    assert_true(False if fu > 0 and tu == 0 else True,
70
+                "We couldn't set Fallback uplinks "
71
+                "if amount of teaming uplinks equals zero."
72
+                "tu = {0}, fu = {1}".format(tu, fu))
73
+
74
+    map_sw_cl = map(lambda x, y: "{0}:{1}".format(x, y),
75
+                    VCENTER_CLUSTERS, DVS_SWITCHES)
76
+    if any([tu, fu]):
77
+        assert_true(tu + fu <= len(DVS_UPLINKS), 'Not enough uplinks')
78
+        data = [c + ':' + ';'.join(DVS_UPLINKS[:tu]) for c in map_sw_cl]
79
+        if fu > 0:
80
+            data = [v + ':' + ';'.join(DVS_UPLINKS[tu:tu+fu]) for v in data]
81
+        return '\n'.join(data if multiclusters else data[0:1])
82
+    else:
83
+        return '\n'.join(map_sw_cl if multiclusters else map_sw_cl[0:1])

Loading…
Cancel
Save