Bugfix: Only add keyword "external_network" to the first network 25/17625/3
authorwu.zhihui <wu.zhihui1@zte.com.cn>
Wed, 27 Jul 2016 12:48:55 +0000 (20:48 +0800)
committerwu.zhihui <wu.zhihui1@zte.com.cn>
Thu, 28 Jul 2016 05:54:58 +0000 (13:54 +0800)
In test case yaml file, when vm need three networks and enable
floating ip true, it should only add keyword "external_network"
to the first one.

'networks': {'test': {'cidr': '10.0.1.0/24', 'external_network':
'admin_floating_net'}, 'test3': {'cidr': '10.0.3.0/24'},
'test2': {'cidr': '10.0.2.0/24'}}

JIRA:YARDSTICK-309

Change-Id: I1126955749b598b8c5460ac75843c1939b4f8443
Signed-off-by: wu.zhihui <wu.zhihui1@zte.com.cn>
yardstick/benchmark/contexts/model.py
yardstick/cmd/commands/task.py

index 2cf31f6..d31f4af 100644 (file)
@@ -201,12 +201,12 @@ class Server(Object):
                                              port_name,
                                              network.router.stack_if_name,
                                              self.secgroup_name)
-                self.floating_ip_assoc["stack_name"] = \
-                    server_name + "-fip-assoc"
-                template.add_floating_ip_association(
-                    self.floating_ip_assoc["stack_name"],
-                    self.floating_ip["stack_name"],
-                    port_name)
+                    self.floating_ip_assoc["stack_name"] = \
+                        server_name + "-fip-assoc"
+                    template.add_floating_ip_association(
+                        self.floating_ip_assoc["stack_name"],
+                        self.floating_ip["stack_name"],
+                        port_name)
 
         template.add_server(server_name, self.image, self.flavor,
                             ports=port_name_list,
index 18b72e7..69652c3 100644 (file)
@@ -275,10 +275,16 @@ class TaskParser(object):
         for cfg_attrs in context_cfgs:
             context_type = cfg_attrs.get("type", "Heat")
             if "Heat" == context_type and "networks" in cfg_attrs:
+                # bugfix: if there are more than one network,
+                # only add "external_network" on first one.
+                # the name of netwrok should follow this rule:
+                # test, test2, test3 ...
+                # sort network with the length of network's name
+                sorted_networks = sorted(cfg_attrs["networks"].keys())
                 # config external_network based on env var
-                for _, attrs in cfg_attrs["networks"].items():
-                    attrs["external_network"] = os.environ.get(
-                        'EXTERNAL_NETWORK', 'net04_ext')
+                cfg_attrs["networks"][sorted_networks[0]]["external_network"] \
+                    = os.environ.get("EXTERNAL_NETWORK", "net04_ext")
+
             context = Context.get(context_type)
             context.init(cfg_attrs)