cleanup networking api, rest and cli and unittest
authorstevenvanrossem <steven.vanrossem@intec.ugent.be>
Tue, 6 Jun 2017 08:33:19 +0000 (10:33 +0200)
committerstevenvanrossem <steven.vanrossem@intec.ugent.be>
Tue, 6 Jun 2017 08:33:19 +0000 (10:33 +0200)
43 files changed:
src/emuvim/api/openstack/__init__.py [changed mode: 0644->0755]
src/emuvim/api/openstack/chain_api.py [changed mode: 0644->0755]
src/emuvim/api/openstack/compute.py [changed mode: 0644->0755]
src/emuvim/api/openstack/docker_util.py [changed mode: 0644->0755]
src/emuvim/api/openstack/heat_parser.py [changed mode: 0644->0755]
src/emuvim/api/openstack/ip_handler.py [changed mode: 0644->0755]
src/emuvim/api/openstack/manage.py [changed mode: 0644->0755]
src/emuvim/api/openstack/openstack_api_endpoint.py [changed mode: 0644->0755]
src/emuvim/api/openstack/openstack_dummies/__init__.py [changed mode: 0644->0755]
src/emuvim/api/openstack/openstack_dummies/base_openstack_dummy.py [changed mode: 0644->0755]
src/emuvim/api/openstack/openstack_dummies/glance_dummy_api.py [changed mode: 0644->0755]
src/emuvim/api/openstack/openstack_dummies/heat_dummy_api.py [changed mode: 0644->0755]
src/emuvim/api/openstack/openstack_dummies/keystone_dummy_api.py [changed mode: 0644->0755]
src/emuvim/api/openstack/openstack_dummies/neutron_dummy_api.py [changed mode: 0644->0755]
src/emuvim/api/openstack/openstack_dummies/nova_dummy_api.py [changed mode: 0644->0755]
src/emuvim/api/openstack/resources/__init__.py [changed mode: 0644->0755]
src/emuvim/api/openstack/resources/image.py [changed mode: 0644->0755]
src/emuvim/api/openstack/resources/instance_flavor.py [changed mode: 0644->0755]
src/emuvim/api/openstack/resources/load_balancer.py [changed mode: 0644->0755]
src/emuvim/api/openstack/resources/model.py [changed mode: 0644->0755]
src/emuvim/api/openstack/resources/net.py [changed mode: 0644->0755]
src/emuvim/api/openstack/resources/port.py [changed mode: 0644->0755]
src/emuvim/api/openstack/resources/resource.py [changed mode: 0644->0755]
src/emuvim/api/openstack/resources/router.py [changed mode: 0644->0755]
src/emuvim/api/openstack/resources/server.py [changed mode: 0644->0755]
src/emuvim/api/openstack/resources/stack.py [changed mode: 0644->0755]
src/emuvim/api/openstack/resources/template.py [changed mode: 0644->0755]
src/emuvim/api/rest/network.py
src/emuvim/cli/rest/network.py
src/emuvim/dashboard/js/graph.json [changed mode: 0644->0755]
src/emuvim/dcemulator/net.py
src/emuvim/examples/demo_emulator_mano_integration.py [changed mode: 0644->0755]
src/emuvim/examples/demo_topo_3pop.py
src/emuvim/examples/profiling.py [changed mode: 0644->0755]
src/emuvim/test/api_base.py
src/emuvim/test/test-initial-template.yml [changed mode: 0644->0755]
src/emuvim/test/test-scaleout-template.yml [changed mode: 0644->0755]
src/emuvim/test/unittests/test_emulator.py
src/emuvim/test/unittests/test_heatapi_keystone_get_token.json [changed mode: 0644->0755]
src/emuvim/test/unittests/test_heatapi_template_chaining.json [changed mode: 0644->0755]
src/emuvim/test/unittests/test_heatapi_template_create_stack.json [changed mode: 0644->0755]
src/emuvim/test/unittests/test_heatapi_template_update_stack.json [changed mode: 0644->0755]
src/emuvim/test/unittests/test_restapi.py

old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
index bce10fc..0479ee6 100755 (executable)
@@ -90,7 +90,6 @@ class NetworkAction(Resource):
             if data is None:
                 data = {}
 
-            logging.info("data: {}".format(data))
             vnf_src_name = data.get("vnf_src_name")
             vnf_dst_name = data.get("vnf_dst_name")
             vnf_src_interface = data.get("vnf_src_interface")
index b4a1a89..82fe99f 100755 (executable)
@@ -26,10 +26,8 @@ acknowledge the contributions of their colleagues of the SONATA
 partner consortium (www.sonata-nfv.eu).
 """
 from requests import get,put, delete
-import pprint
 import argparse
 
-pp = pprint.PrettyPrinter(indent=4)
 
 class RestApiClient():
 
@@ -57,7 +55,7 @@ class RestApiClient():
 
         response = put("{0}/restapi/network".format(args.get("endpoint")),
                        params=params)
-        pp.pprint(response.text)
+        print(self._nice_print(response.text))
 
     def remove(self, args):
         params = self._create_dict(
@@ -73,7 +71,7 @@ class RestApiClient():
 
         response = delete("{0}/restapi/network".format(args.get("endpoint")),
                           params=params)
-        pp.pprint(response.text)
+        print(self._nice_print(response.text))
 
     def _parse_vnf_name(self, vnf_name_str):
         vnf_name = vnf_name_str.split(':')[0]
@@ -90,6 +88,12 @@ class RestApiClient():
     def _create_dict(self, **kwargs):
         return kwargs
 
+    def _nice_print(self, text):
+        # some modules seem to return unicode strings where newlines, other special characters are escaped
+        text = str(text).replace('\\n', '\n')
+        text = str(text).replace('\\"', '"')
+        return text
+
 parser = argparse.ArgumentParser(description='son-emu-cli network')
 parser.add_argument(
     "command",
@@ -108,7 +112,7 @@ parser.add_argument(
     "--weight", "-w", dest="weight",
     help="weight edge attribute to calculate the path")
 parser.add_argument(
-    "--priority", "-p", dest="priority", default="0",
+    "--priority", "-p", dest="priority", default="1000",
     help="priority of flow rule")
 parser.add_argument(
     "--match", "-m", dest="match",
@@ -117,7 +121,7 @@ parser.add_argument(
     "--bidirectional", "-b", dest="bidirectional", action='store_true',
     help="add/remove the flow entries from src to dst and back")
 parser.add_argument(
-    "--cookie", "-c", dest="cookie",
+    "--cookie", "-c", dest="cookie", default="10",
     help="cookie for this flow, as easy to use identifier (eg. per tenant/service)")
 parser.add_argument(
     "--endpoint", "-e", dest="endpoint",
old mode 100644 (file)
new mode 100755 (executable)
index 5dfcbcd..7efb3f0 100755 (executable)
@@ -33,6 +33,7 @@ from subprocess import Popen
 import re
 import requests
 import os
+import json
 
 from mininet.net import Containernet
 from mininet.node import Controller, DefaultController, OVSSwitch, OVSKernelSwitch, Docker, RemoteController
@@ -50,6 +51,11 @@ LOG.setLevel(logging.DEBUG)
 # default CPU period used for cpu percentage-based cfs values (microseconds)
 CPU_PERIOD = 1000000
 
+# default priority setting for added flow-rules
+DEFAULT_PRIORITY = 1000
+# default cookie number for new flow-rules
+DEFAULT_COOKIE = 10
+
 class DCNetwork(Containernet):
     """
     Wraps the original Mininet/Containernet class and provides
@@ -710,7 +716,15 @@ class DCNetwork(Containernet):
                 switch_inport_nr = self.DCNetwork_graph[current_hop][next_hop][0]['dst_port_nr']
                 current_hop = next_hop
 
-        return "path {2} between {0} and {1}".format(vnf_src_name, vnf_dst_name, cmd)
+        flow_options = {
+            'priority':kwargs.get('priority', DEFAULT_PRIORITY),
+            'cookie':kwargs.get('cookie', DEFAULT_COOKIE),
+            'vlan':kwargs['vlan'],
+            'path':kwargs['path'],
+            'match_input':kwargs.get('match')
+        }
+        flow_options_str = json.dumps(flow_options, indent=1)
+        return "success: {2} between {0} and {1} with options: {3}".format(vnf_src_name, vnf_dst_name, cmd, flow_options_str)
 
     def _set_flow_entry_ryu_rest(self, node, switch_inport_nr, switch_outport_nr, **kwargs):
         match = 'in_port=%s' % switch_inport_nr
@@ -722,7 +736,7 @@ class DCNetwork(Containernet):
         index = kwargs.get('pathindex')
 
         vlan = kwargs.get('vlan')
-        priority = kwargs.get('priority')
+        priority = kwargs.get('priority', DEFAULT_PRIORITY)
         # flag to not set the ovs port vlan tag
         skip_vlan_tag = kwargs.get('skip_vlan_tag')
         # table id to put this flowentry
old mode 100644 (file)
new mode 100755 (executable)
index 992d972..f13b9d3
@@ -20,7 +20,7 @@ class DemoTopology(DCNetwork):
         Initialize multi PoP emulator network.
         """
         super(DemoTopology, self).__init__(
-            monitor=False,
+            monitor=True,
             enable_learning=True
         )
         # define members for later use
index 8020fc8..aee5f91 100755 (executable)
@@ -47,7 +47,7 @@ logging.basicConfig(level=logging.INFO)
 
 def create_topology1():
     # create topology
-    net = DCNetwork(controller=RemoteController, monitor=False, enable_learning=True)
+    net = DCNetwork(controller=RemoteController, monitor=True, enable_learning=True)
     dc1 = net.addDatacenter("dc1")
     dc2 = net.addDatacenter("dc2")
     dc3 = net.addDatacenter("dc3")
old mode 100644 (file)
new mode 100755 (executable)
index 57d4aa5..3464f45 100755 (executable)
@@ -68,7 +68,7 @@ class SimpleTestTopology(unittest.TestCase):
         specific controller functionality.
         """
         self.net = DCNetwork(controller=controller, **kwargs)
-        self.api = RestApiEndpoint("127.0.0.1", 5001)
+        self.api = RestApiEndpoint("127.0.0.1", 5001, self.net)
         # add some switches
         # start from s1 because ovs does not like to have dpid = 0
         # and switch name-number is being used by mininet to set the dpid
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
index b5612a1..94db55f 100755 (executable)
@@ -117,6 +117,57 @@ class testEmulatorTopology( SimpleTestTopology ):
 
 class testEmulatorNetworking( SimpleTestTopology ):
 
+    def testSDNChainingSingleService_withLearning(self):
+        """
+        Create a two data centers and interconnect them with additional
+        switches between them.
+        Uses Ryu SDN controller.
+        Connect the Docker hosts to different datacenters and setup the links between.
+        """
+        # create network
+        self.createNet(
+            nswitches=3, ndatacenter=2, nhosts=0, ndockers=0,
+            autolinkswitches=True,
+            controller=RemoteController,
+            enable_learning=True)
+        # setup links
+        self.net.addLink(self.dc[0], self.s[0])
+        self.net.addLink(self.s[2], self.dc[1])
+        # start Mininet network
+        self.startNet()
+
+        # add compute resources
+        vnf1 = self.dc[0].startCompute("vnf1", network=[{'id':'intf1', 'ip':'10.0.10.1/24'}])
+        vnf2 = self.dc[1].startCompute("vnf2", network=[{'id':'intf2', 'ip':'10.0.10.2/24'}])
+        # check number of running nodes
+        self.assertTrue(len(self.getContainernetContainers()) == 2)
+        self.assertTrue(len(self.net.hosts) == 2)
+        self.assertTrue(len(self.net.switches) == 5)
+        # check status
+        # check get status
+        s1 = self.dc[0].containers.get("vnf1").getStatus()
+        print s1
+        self.assertTrue(s1["name"] == "vnf1")
+        self.assertTrue(s1["state"]["Running"])
+        self.assertTrue(s1["network"][0]['intf_name'] == 'intf1')
+        self.assertTrue(s1["network"][0]['ip'] == '10.0.10.1/24')
+
+        s2 = self.dc[1].containers.get("vnf2").getStatus()
+        print s2
+        self.assertTrue(s2["name"] == "vnf2")
+        self.assertTrue(s2["state"]["Running"])
+        self.assertTrue(s2["network"][0]['intf_name'] == 'intf2')
+        self.assertTrue(s2["network"][0]['ip'] == '10.0.10.2/24')
+
+        # should be connected because learning = True
+        self.assertTrue(self.net.ping([vnf1, vnf2]) <= 0.0)
+        # setup links
+        self.net.setChain('vnf1', 'vnf2', 'intf1', 'intf2', bidirectional=True, cmd='add-flow')
+        # should still be connected
+        self.assertTrue(self.net.ping([vnf1, vnf2]) <= 0.0)
+        # stop Mininet network
+        self.stopNet()
+
     def testSDNChainingSingleService(self):
         """
         Create a two data centers and interconnect them with additional
index ea0b693..268b12b 100755 (executable)
@@ -92,14 +92,19 @@ class testRestApi(SimpleTestTopology):
 
         print('network add vnf1 vnf2->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
         print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
-        subprocess.call("son-emu-cli network add -src vnf1 -dst vnf2 -b -c 10", shell=True)
+        output = subprocess.check_output("son-emu-cli network add -src vnf1 -dst vnf2 -b -c 10", shell=True)
+        self.assertTrue("add-flow" in output)
+        self.assertTrue("success" in output)
+
         print('network remove vnf1 vnf2->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
         print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
-        subprocess.call("son-emu-cli network remove -src vnf1 -dst vnf2 -b", shell=True)
+        output = subprocess.check_output("son-emu-cli network remove -src vnf1 -dst vnf2 -b", shell=True)
+        self.assertTrue("del-flows" in output)
+        self.assertTrue("success" in output)
 
         print('>>>>> checking --> son-emu-cli compute stop -d datacenter0 -n vnf2 ->>>>>>')
         print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
-        subprocess.call("son-emu-cli compute stop -d datacenter0 -n vnf2", shell=True)
+        output = subprocess.check_output("son-emu-cli compute stop -d datacenter0 -n vnf2", shell=True)
 
         # check number of running nodes
         self.assertTrue(len(self.getContainernetContainers()) == 2)
@@ -111,7 +116,6 @@ class testRestApi(SimpleTestTopology):
 
         print('>>>>> checking --> son-emu-cli compute list ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
         print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
-        subprocess.call("son-emu-cli compute list", shell=True)
         output = subprocess.check_output("son-emu-cli compute list", shell=True)
 
         # check datacenter list result
@@ -119,7 +123,6 @@ class testRestApi(SimpleTestTopology):
 
         print('>>>>> checking --> son-emu-cli compute status -d datacenter0 -n vnf1 ->>>>')
         print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
-        subprocess.call("son-emu-cli compute status -d datacenter0 -n vnf1", shell=True)
         output = subprocess.check_output("son-emu-cli compute status -d datacenter0 -n vnf1", shell=True)
         output = ast.literal_eval(output)
 
@@ -129,18 +132,13 @@ class testRestApi(SimpleTestTopology):
 
         print('>>>>> checking --> son-emu-cli datacenter list ->>>>>>>>>>>>>>>>>>>>>>>>>>')
         print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
-        subprocess.call("son-emu-cli datacenter list", shell=True)
         output = subprocess.check_output("son-emu-cli datacenter list", shell=True)
-
         # check datacenter list result
-
         self.assertTrue("datacenter0" in output)
 
         print('->>>>> checking --> son-emu-cli datacenter status -d datacenter0 ->>>>>>>>')
         print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
-        subprocess.call("son-emu-cli datacenter status -d datacenter0", shell=True)
         output = subprocess.check_output("son-emu-cli datacenter status -d datacenter0", shell=True)
-
         # check datacenter status result
         self.assertTrue("datacenter0" in output)