From 7f8e8408ef6f118e55e9066c02c70689501b3d2b Mon Sep 17 00:00:00 2001 From: peusterm Date: Sun, 28 Feb 2016 18:38:10 +0100 Subject: [PATCH 01/16] Extended network API to support multiple interfaces in a single Docker container. Closes #11. --- emuvim/api/zerorpcapi.py | 10 +++++++++- emuvim/cli/compute.py | 11 +++++++---- emuvim/dcemulator/node.py | 22 ++++++++++++++++------ 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/emuvim/api/zerorpcapi.py b/emuvim/api/zerorpcapi.py index fd814b3..59b960c 100755 --- a/emuvim/api/zerorpcapi.py +++ b/emuvim/api/zerorpcapi.py @@ -57,7 +57,15 @@ class MultiDatacenterApi(object): self.dcs = dcs def compute_action_start(self, dc_label, compute_name, image, command, network): - # network e.g. {"ip": "10.0.0.254/8"} + """ + Start a new compute instance: A docker container + :param dc_label: name of the DC + :param compute_name: compute container name + :param image: image name + :param command: command to execute + :param network: + :return: networks list({"ip": "10.0.0.254/8"}, {"ip": "11.0.0.254/24"}) + """ # TODO what to return UUID / given name / internal name ? logging.debug("RPC CALL: compute start") try: diff --git a/emuvim/cli/compute.py b/emuvim/cli/compute.py index 15fea91..70de20a 100755 --- a/emuvim/cli/compute.py +++ b/emuvim/cli/compute.py @@ -27,15 +27,17 @@ class ZeroRpcClient(object): print "Command not implemented." def start(self, args): - network = {} + nw_list = list() if args.get("network") is not None: - network = {"ip": args.get("network")} + networks = args.get("network").split(",") + for nw in networks: + nw_list.append({"ip": nw}) r = self.c.compute_action_start( args.get("datacenter"), args.get("name"), args.get("image"), args.get("docker_command"), - network) + nw_list) pp.pprint(r) def stop(self, args): @@ -97,7 +99,8 @@ parser.add_argument( help="Startup command of the container e.g. './start.sh'") parser.add_argument( "--net", dest="network", - help="Network properties of compute instance e.g. '10.0.0.123/8'") + help="Network properties of compute instance e.g. \ + '10.0.0.123/8' or '10.0.0.123/8,11.0.0.123/24' for multiple interfaces.") def main(argv): diff --git a/emuvim/dcemulator/node.py b/emuvim/dcemulator/node.py index 13007eb..336126c 100755 --- a/emuvim/dcemulator/node.py +++ b/emuvim/dcemulator/node.py @@ -99,13 +99,15 @@ class Datacenter(object): def start(self): pass - def startCompute(self, name, image=None, command=None,network=None): + def startCompute(self, name, image=None, command=None, network=None): """ Create a new container as compute resource and connect it to this data center. - - TODO: This interface will change to support multiple networks to which - a single container can be connected. + :param name: name (string) + :param image: image name (string) + :param command: command (string) + :param network: networks list({"ip": "10.0.0.254/8"}, {"ip": "11.0.0.254/24"}) + :return: """ assert name is not None # no duplications @@ -116,9 +118,17 @@ class Datacenter(object): image = "ubuntu" if network is None: network = {} # {"ip": "10.0.0.254/8"} - # create the container and connect it to the given network + if isinstance(network, dict): + network = [network] # if we have only one network, put it in a list + if isinstance(network, list): + if len(network) < 1: + network.append({}) + + # create the container d = self.net.addDocker("%s" % (name), dimage=image, dcmd=command) - self.net.addLink(d, self.switch, params1=network) + # connect all given networks + for nw in network: + self.net.addLink(d, self.switch, params1=nw) # do bookkeeping self.containers[name] = d d.datacenter = self -- 2.17.1 From cf3503812e7562bb771a03f7e7138cd9660f425b Mon Sep 17 00:00:00 2001 From: cgeoffroy Date: Wed, 2 Mar 2016 16:39:58 +0100 Subject: [PATCH 02/16] Fix: only list and remove the dockernet's containers This PR modify an emuvim test to use the custom label applied on the dockernet's containers. Otherwise, third-party containers were listed by the test, which ended in a failure. The teardown strategy has been updated to avoid removing third-party containers. It requires the latest dockernet version on the `dockernet-sonata` branch (https://github.com/mpeuster/dockernet/tree/dockernet-sonata). --- emuvim/test/test_emulator.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/emuvim/test/test_emulator.py b/emuvim/test/test_emulator.py index 8b756b9..ef22a22 100755 --- a/emuvim/test/test_emulator.py +++ b/emuvim/test/test_emulator.py @@ -81,6 +81,12 @@ class simpleTestTopology( unittest.TestCase ): base_url='unix://var/run/docker.sock') return self.docker_cli + def getDockernetContainers(self): + """ + List the containers managed by dockernet + """ + return self.getDockerCli().containers(filters={"label": "com.dockernet"}) + @staticmethod def setUp(): pass @@ -91,7 +97,7 @@ class simpleTestTopology( unittest.TestCase ): # make sure that all pending docker containers are killed with open(os.devnull, 'w') as devnull: subprocess.call( - "sudo docker rm -f $(sudo docker ps -a -q)", + "sudo docker rm -f $(sudo docker ps --filter 'label=com.dockernet' -a -q)", stdout=devnull, stderr=devnull, shell=True) @@ -117,7 +123,7 @@ class testEmulatorTopology( simpleTestTopology ): # start Mininet network self.startNet() # check number of running nodes - assert(len(self.getDockerCli().containers()) == 0) + assert(len(self.getDockernetContainers()) == 0) assert(len(self.net.hosts) == 2) assert(len(self.net.switches) == 1) # check connectivity by using ping @@ -138,7 +144,7 @@ class testEmulatorTopology( simpleTestTopology ): # start Mininet network self.startNet() # check number of running nodes - assert(len(self.getDockerCli().containers()) == 0) + assert(len(self.getDockernetContainers()) == 0) assert(len(self.net.hosts) == 2) assert(len(self.net.switches) == 2) # check connectivity by using ping @@ -163,7 +169,7 @@ class testEmulatorTopology( simpleTestTopology ): # start Mininet network self.startNet() # check number of running nodes - assert(len(self.getDockerCli().containers()) == 0) + assert(len(self.getDockernetContainers()) == 0) assert(len(self.net.hosts) == 2) assert(len(self.net.switches) == 5) # check connectivity by using ping @@ -194,7 +200,7 @@ class testEmulatorCompute( simpleTestTopology ): # add compute resources vnf1 = self.dc[0].startCompute("vnf1") # check number of running nodes - assert(len(self.getDockerCli().containers()) == 1) + assert(len(self.getDockernetContainers()) == 1) assert(len(self.net.hosts) == 2) assert(len(self.net.switches) == 1) # check compute list result @@ -220,7 +226,7 @@ class testEmulatorCompute( simpleTestTopology ): # add compute resources vnf1 = self.dc[0].startCompute("vnf1") # check number of running nodes - assert(len(self.getDockerCli().containers()) == 1) + assert(len(self.getDockernetContainers()) == 1) assert(len(self.net.hosts) == 2) assert(len(self.net.switches) == 1) # check compute list result @@ -230,7 +236,7 @@ class testEmulatorCompute( simpleTestTopology ): # remove compute resources self.dc[0].stopCompute("vnf1") # check number of running nodes - assert(len(self.getDockerCli().containers()) == 0) + assert(len(self.getDockernetContainers()) == 0) assert(len(self.net.hosts) == 1) assert(len(self.net.switches) == 1) # check compute list result @@ -252,7 +258,7 @@ class testEmulatorCompute( simpleTestTopology ): # add compute resources vnf1 = self.dc[0].startCompute("vnf1") # check number of running nodes - assert(len(self.getDockerCli().containers()) == 1) + assert(len(self.getDockernetContainers()) == 1) assert(len(self.net.hosts) == 2) assert(len(self.net.switches) == 1) # check compute list result @@ -286,7 +292,7 @@ class testEmulatorCompute( simpleTestTopology ): vnf1 = self.dc[0].startCompute("vnf1") vnf2 = self.dc[1].startCompute("vnf2") # check number of running nodes - assert(len(self.getDockerCli().containers()) == 2) + assert(len(self.getDockernetContainers()) == 2) assert(len(self.net.hosts) == 2) assert(len(self.net.switches) == 5) # check compute list result @@ -315,7 +321,7 @@ class testEmulatorCompute( simpleTestTopology ): vnf1 = self.dc[0].startCompute("vnf1") vnf2 = self.dc[1].startCompute("vnf2") # check number of running nodes - assert(len(self.getDockerCli().containers()) == 2) + assert(len(self.getDockernetContainers()) == 2) assert(len(self.net.hosts) == 2) assert(len(self.net.switches) == 5) # check compute list result @@ -326,7 +332,7 @@ class testEmulatorCompute( simpleTestTopology ): # remove compute resources self.dc[0].stopCompute("vnf1") # check number of running nodes - assert(len(self.getDockerCli().containers()) == 1) + assert(len(self.getDockernetContainers()) == 1) assert(len(self.net.hosts) == 1) assert(len(self.net.switches) == 5) # check compute list result -- 2.17.1 From 3eef9fde234a4379d80e0435bac9ce650407a895 Mon Sep 17 00:00:00 2001 From: cgeoffroy Date: Thu, 3 Mar 2016 18:18:13 +0100 Subject: [PATCH 03/16] Moving emuvim into the src directory --- README.md | 8 ++++---- {emuvim => src/emuvim}/api/__init__.py | 0 {emuvim => src/emuvim}/api/zerorpcapi.py | 0 {emuvim => src/emuvim}/api/zerorpcapi_DCNetwork.py | 0 {emuvim => src/emuvim}/cli/__init__.py | 0 {emuvim => src/emuvim}/cli/compute.py | 0 {emuvim => src/emuvim}/cli/datacenter.py | 0 {emuvim => src/emuvim}/cli/monitor.py | 0 {emuvim => src/emuvim}/cli/network.py | 0 {emuvim => src/emuvim}/cli/son-emu-cli | 0 {emuvim => src/emuvim}/dcemulator/__init__.py | 0 {emuvim => src/emuvim}/dcemulator/link.py | 0 {emuvim => src/emuvim}/dcemulator/monitoring.py | 0 {emuvim => src/emuvim}/dcemulator/net.py | 0 {emuvim => src/emuvim}/dcemulator/node.py | 0 {emuvim => src/emuvim}/example_topology.py | 0 {emuvim => src/emuvim}/test/__main__.py | 0 {emuvim => src/emuvim}/test/runner.py | 0 {emuvim => src/emuvim}/test/test_api_zerorpc.py | 0 {emuvim => src/emuvim}/test/test_emulator.py | 0 20 files changed, 4 insertions(+), 4 deletions(-) rename {emuvim => src/emuvim}/api/__init__.py (100%) rename {emuvim => src/emuvim}/api/zerorpcapi.py (100%) rename {emuvim => src/emuvim}/api/zerorpcapi_DCNetwork.py (100%) rename {emuvim => src/emuvim}/cli/__init__.py (100%) rename {emuvim => src/emuvim}/cli/compute.py (100%) rename {emuvim => src/emuvim}/cli/datacenter.py (100%) rename {emuvim => src/emuvim}/cli/monitor.py (100%) rename {emuvim => src/emuvim}/cli/network.py (100%) rename {emuvim => src/emuvim}/cli/son-emu-cli (100%) rename {emuvim => src/emuvim}/dcemulator/__init__.py (100%) rename {emuvim => src/emuvim}/dcemulator/link.py (100%) rename {emuvim => src/emuvim}/dcemulator/monitoring.py (100%) rename {emuvim => src/emuvim}/dcemulator/net.py (100%) rename {emuvim => src/emuvim}/dcemulator/node.py (100%) rename {emuvim => src/emuvim}/example_topology.py (100%) rename {emuvim => src/emuvim}/test/__main__.py (100%) rename {emuvim => src/emuvim}/test/runner.py (100%) rename {emuvim => src/emuvim}/test/test_api_zerorpc.py (100%) rename {emuvim => src/emuvim}/test/test_emulator.py (100%) diff --git a/README.md b/README.md index c3fa61f..e2b6658 100755 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Contributors: * (This will be replaced / extended by a REST API later) ### Project structure -* **emuvim/** all emulator code +* **src/emuvim/** all emulator code * **api/** Data center API endpoint implementations (zerorpc, OpenStack REST, ...) * **cli/** CLI client to interact with a running emulator * **dcemulator/** Dockernet wrapper that introduces the notion of data centers and API endpoints @@ -44,10 +44,10 @@ Automatic installation is provide through Ansible playbooks. ### Run * First terminal: - * `cd ~/son-emu/emuvim` + * `cd ~/son-emu/src/emuvim` * `sudo python example_topology.py` * Second terminal: - * `cd ~/son-emu/emuvim/cli` + * `cd ~/son-emu/src/emuvim/cli` * `./son-emu-cli compute start -d datacenter1 -n vnf1` * `./son-emu-cli compute start -d datacenter1 -n vnf2` * `./son-emu-cli compute list` @@ -61,7 +61,7 @@ Automatic installation is provide through Ansible playbooks. * `./start_example_chain` sets up an example service chain, using the example docker container from `package_samples` https://github.com/sonata-nfv/packaging_samples/tree/master/VNFs ### Run Unit Tests -* `cd ~/son-emu/emuvim` +* `cd ~/son-emu/src/emuvim` * `sudo python test` or `sudo python test -v` for more outputs ### CLI diff --git a/emuvim/api/__init__.py b/src/emuvim/api/__init__.py similarity index 100% rename from emuvim/api/__init__.py rename to src/emuvim/api/__init__.py diff --git a/emuvim/api/zerorpcapi.py b/src/emuvim/api/zerorpcapi.py similarity index 100% rename from emuvim/api/zerorpcapi.py rename to src/emuvim/api/zerorpcapi.py diff --git a/emuvim/api/zerorpcapi_DCNetwork.py b/src/emuvim/api/zerorpcapi_DCNetwork.py similarity index 100% rename from emuvim/api/zerorpcapi_DCNetwork.py rename to src/emuvim/api/zerorpcapi_DCNetwork.py diff --git a/emuvim/cli/__init__.py b/src/emuvim/cli/__init__.py similarity index 100% rename from emuvim/cli/__init__.py rename to src/emuvim/cli/__init__.py diff --git a/emuvim/cli/compute.py b/src/emuvim/cli/compute.py similarity index 100% rename from emuvim/cli/compute.py rename to src/emuvim/cli/compute.py diff --git a/emuvim/cli/datacenter.py b/src/emuvim/cli/datacenter.py similarity index 100% rename from emuvim/cli/datacenter.py rename to src/emuvim/cli/datacenter.py diff --git a/emuvim/cli/monitor.py b/src/emuvim/cli/monitor.py similarity index 100% rename from emuvim/cli/monitor.py rename to src/emuvim/cli/monitor.py diff --git a/emuvim/cli/network.py b/src/emuvim/cli/network.py similarity index 100% rename from emuvim/cli/network.py rename to src/emuvim/cli/network.py diff --git a/emuvim/cli/son-emu-cli b/src/emuvim/cli/son-emu-cli similarity index 100% rename from emuvim/cli/son-emu-cli rename to src/emuvim/cli/son-emu-cli diff --git a/emuvim/dcemulator/__init__.py b/src/emuvim/dcemulator/__init__.py similarity index 100% rename from emuvim/dcemulator/__init__.py rename to src/emuvim/dcemulator/__init__.py diff --git a/emuvim/dcemulator/link.py b/src/emuvim/dcemulator/link.py similarity index 100% rename from emuvim/dcemulator/link.py rename to src/emuvim/dcemulator/link.py diff --git a/emuvim/dcemulator/monitoring.py b/src/emuvim/dcemulator/monitoring.py similarity index 100% rename from emuvim/dcemulator/monitoring.py rename to src/emuvim/dcemulator/monitoring.py diff --git a/emuvim/dcemulator/net.py b/src/emuvim/dcemulator/net.py similarity index 100% rename from emuvim/dcemulator/net.py rename to src/emuvim/dcemulator/net.py diff --git a/emuvim/dcemulator/node.py b/src/emuvim/dcemulator/node.py similarity index 100% rename from emuvim/dcemulator/node.py rename to src/emuvim/dcemulator/node.py diff --git a/emuvim/example_topology.py b/src/emuvim/example_topology.py similarity index 100% rename from emuvim/example_topology.py rename to src/emuvim/example_topology.py diff --git a/emuvim/test/__main__.py b/src/emuvim/test/__main__.py similarity index 100% rename from emuvim/test/__main__.py rename to src/emuvim/test/__main__.py diff --git a/emuvim/test/runner.py b/src/emuvim/test/runner.py similarity index 100% rename from emuvim/test/runner.py rename to src/emuvim/test/runner.py diff --git a/emuvim/test/test_api_zerorpc.py b/src/emuvim/test/test_api_zerorpc.py similarity index 100% rename from emuvim/test/test_api_zerorpc.py rename to src/emuvim/test/test_api_zerorpc.py diff --git a/emuvim/test/test_emulator.py b/src/emuvim/test/test_emulator.py similarity index 100% rename from emuvim/test/test_emulator.py rename to src/emuvim/test/test_emulator.py -- 2.17.1 From 1aefccedc72b31481c01323c4925701079f5bbb8 Mon Sep 17 00:00:00 2001 From: cgeoffroy Date: Thu, 3 Mar 2016 18:19:16 +0100 Subject: [PATCH 04/16] Updating the son-emu-cli filename to a standard module name --- src/emuvim/cli/{son-emu-cli => son_emu_cli.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/emuvim/cli/{son-emu-cli => son_emu_cli.py} (100%) diff --git a/src/emuvim/cli/son-emu-cli b/src/emuvim/cli/son_emu_cli.py similarity index 100% rename from src/emuvim/cli/son-emu-cli rename to src/emuvim/cli/son_emu_cli.py -- 2.17.1 From 26fded288d29c090e82618ca0930c8d7ecefc884 Mon Sep 17 00:00:00 2001 From: cgeoffroy Date: Thu, 3 Mar 2016 18:20:02 +0100 Subject: [PATCH 05/16] Creating a son-emu-cli symbolic name for retro-compatibility --- src/emuvim/cli/son-emu-cli | 1 + 1 file changed, 1 insertion(+) create mode 120000 src/emuvim/cli/son-emu-cli diff --git a/src/emuvim/cli/son-emu-cli b/src/emuvim/cli/son-emu-cli new file mode 120000 index 0000000..9f1eb84 --- /dev/null +++ b/src/emuvim/cli/son-emu-cli @@ -0,0 +1 @@ +son_emu_cli.py \ No newline at end of file -- 2.17.1 From 840f1795465dfa8927ea3857a864ca8b6fe5588f Mon Sep 17 00:00:00 2001 From: cgeoffroy Date: Thu, 3 Mar 2016 16:53:52 +0100 Subject: [PATCH 06/16] Installing pytest --- .gitignore | 2 ++ ansible/install.yml | 3 +++ conftest.py | 0 3 files changed, 5 insertions(+) create mode 100644 conftest.py diff --git a/.gitignore b/.gitignore index 5cbc2c6..6b050ca 100755 --- a/.gitignore +++ b/.gitignore @@ -62,3 +62,5 @@ target/ #Ipython Notebook .ipynb_checkpoints +#Pytest +.pytest.restart diff --git a/ansible/install.yml b/ansible/install.yml index 1d73779..23df943 100755 --- a/ansible/install.yml +++ b/ansible/install.yml @@ -35,3 +35,6 @@ - name: install oslo.config pip: name=oslo.config + + - name: install pytest + pip: name=pytest diff --git a/conftest.py b/conftest.py new file mode 100644 index 0000000..e69de29 -- 2.17.1 From 9524ad314883db5445b27dfd2c61084a7e7329a2 Mon Sep 17 00:00:00 2001 From: cgeoffroy Date: Thu, 3 Mar 2016 18:24:15 +0100 Subject: [PATCH 07/16] Using absolute import path --- src/emuvim/__init__.py | 0 src/emuvim/cli/son_emu_cli.py | 8 ++++---- src/emuvim/dcemulator/net.py | 4 ++-- src/emuvim/example_topology.py | 2 +- src/emuvim/test/test_emulator.py | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 src/emuvim/__init__.py diff --git a/src/emuvim/__init__.py b/src/emuvim/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/emuvim/cli/son_emu_cli.py b/src/emuvim/cli/son_emu_cli.py index 61cbd43..195fe06 100755 --- a/src/emuvim/cli/son_emu_cli.py +++ b/src/emuvim/cli/son_emu_cli.py @@ -13,10 +13,10 @@ """ import sys -import compute -import network -import datacenter -import monitor +from emuvim.cli import compute +from emuvim.cli import network +from emuvim.cli import datacenter +from emuvim.cli import monitor def main(): if len(sys.argv) < 2: diff --git a/src/emuvim/dcemulator/net.py b/src/emuvim/dcemulator/net.py index 20ab33a..e01e950 100755 --- a/src/emuvim/dcemulator/net.py +++ b/src/emuvim/dcemulator/net.py @@ -14,9 +14,9 @@ from mininet.cli import CLI from mininet.log import setLogLevel, info, debug from mininet.link import TCLink, Link import networkx as nx -from monitoring import DCNetworkMonitor +from emuvim.dcemulator.monitoring import DCNetworkMonitor -from node import Datacenter, EmulatorCompute +from emuvim.dcemulator.node import Datacenter, EmulatorCompute class DCNetwork(Dockernet): diff --git a/src/emuvim/example_topology.py b/src/emuvim/example_topology.py index eba751c..a63bd7f 100755 --- a/src/emuvim/example_topology.py +++ b/src/emuvim/example_topology.py @@ -18,7 +18,7 @@ script. """ import logging from mininet.log import setLogLevel -from dcemulator.net import DCNetwork +from emuvim.dcemulator.net import DCNetwork from api.zerorpcapi import ZeroRpcApiEndpoint from api.zerorpcapi_DCNetwork import ZeroRpcApiEndpointDCNetwork diff --git a/src/emuvim/test/test_emulator.py b/src/emuvim/test/test_emulator.py index ef22a22..06e2da3 100755 --- a/src/emuvim/test/test_emulator.py +++ b/src/emuvim/test/test_emulator.py @@ -11,8 +11,8 @@ import os import time import subprocess import docker -from dcemulator.net import DCNetwork -from dcemulator.node import EmulatorCompute +from emuvim.dcemulator.net import DCNetwork +from emuvim.dcemulator.node import EmulatorCompute from mininet.node import Host, Controller, OVSSwitch, Docker from mininet.link import TCLink from mininet.topo import SingleSwitchTopo, LinearTopo -- 2.17.1 From 9a9bd45b0879a3484990c2efc0106c006ecafe27 Mon Sep 17 00:00:00 2001 From: cgeoffroy Date: Thu, 3 Mar 2016 19:01:59 +0100 Subject: [PATCH 08/16] Creating a setup.py file --- setup.cfg | 2 ++ setup.py | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 setup.cfg create mode 100644 setup.py diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..9af7e6f --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[aliases] +test=pytest \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..dcda018 --- /dev/null +++ b/setup.py @@ -0,0 +1,23 @@ +from setuptools import setup, find_packages + +setup(name='emuvim', + version='0.0.1', + license='TODO', + description='emuvim is a VIM for the SONATA platform', + url='http://github.com/sonata-emu', + author_email='sonata-dev@sonata-nfv.eu', + package_dir={'': 'src'}, + # packages=find_packages('emuvim', exclude=['*.test', '*.test.*', 'test.*', 'test']), + packages=find_packages('src'), + install_requires=[ + 'pyaml', + ], + zip_safe=False, + entry_points={ + 'console_scripts': [ + 'son-emu-cli=emuvim.cli.son_emu_cli:main', + ], + }, + setup_requires=['pytest-runner'], + tests_require=['pytest'], +) -- 2.17.1 From 4c3c8e03246996f21e7e1a2759538a416e677091 Mon Sep 17 00:00:00 2001 From: cgeoffroy Date: Thu, 3 Mar 2016 19:20:47 +0100 Subject: [PATCH 09/16] Fix: moving conftest for tests discovery --- conftest.py => src/emuvim/conftest.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename conftest.py => src/emuvim/conftest.py (100%) diff --git a/conftest.py b/src/emuvim/conftest.py similarity index 100% rename from conftest.py rename to src/emuvim/conftest.py -- 2.17.1 From db9c0ca298abdcf458303821c1f5035b636bce1e Mon Sep 17 00:00:00 2001 From: cgeoffroy Date: Thu, 3 Mar 2016 19:21:48 +0100 Subject: [PATCH 10/16] Updating README and script to the new setup.py install --- README.md | 23 ++++++++++++++--------- start_dcnetwork | 3 +-- start_example_chain | 13 ++++++------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index e2b6658..68e5087 100755 --- a/README.md +++ b/README.md @@ -43,26 +43,31 @@ Automatic installation is provide through Ansible playbooks. ### Run + +In the `~/son-emu` directory: + +* During development: + * `python setup.py develop` +* Otherwise, for a classic installation: + * `python setup.py install` * First terminal: - * `cd ~/son-emu/src/emuvim` - * `sudo python example_topology.py` + * `sudo python src/emuvim/example_topology.py` * Second terminal: - * `cd ~/son-emu/src/emuvim/cli` - * `./son-emu-cli compute start -d datacenter1 -n vnf1` - * `./son-emu-cli compute start -d datacenter1 -n vnf2` - * `./son-emu-cli compute list` + * `son-emu-cli compute start -d datacenter1 -n vnf1` + * `son-emu-cli compute start -d datacenter1 -n vnf2` + * `son-emu-cli compute list` * First terminal: * `dockernet> vnf1 ping -c 2 vnf2` * Second terminal: - * `./son-emu-cli monitor get_rate -vnf vnf1` + * `son-emu-cli monitor get_rate -vnf vnf1` #### Example scripts: * `./start_dcnetwork` starts an example datacenter network with monitoring api endpoint * `./start_example_chain` sets up an example service chain, using the example docker container from `package_samples` https://github.com/sonata-nfv/packaging_samples/tree/master/VNFs ### Run Unit Tests -* `cd ~/son-emu/src/emuvim` -* `sudo python test` or `sudo python test -v` for more outputs +* `cd ~/son-emu` +* `sudo py.test -v src/emuvim` (equivalent to `python setup.py test -v --addopts 'src/emuvim'` but with direct access to the commandline arguments) ### CLI * [Full CLI command documentation](https://github.com/sonata-nfv/son-emu/wiki/CLI-Command-Overview) diff --git a/start_dcnetwork b/start_dcnetwork index aca405b..6deb2c9 100755 --- a/start_dcnetwork +++ b/start_dcnetwork @@ -1,7 +1,6 @@ #!/bin/bash # start DC Network -cd emuvim/ -python example_topology.py +python src/emuvim/example_topology.py diff --git a/start_example_chain b/start_example_chain index 935a766..9a130a6 100755 --- a/start_example_chain +++ b/start_example_chain @@ -2,15 +2,14 @@ # deploy VNFs -cd emuvim/cli/ -./son-emu-cli compute start -d datacenter1 -n tsrc -i traffic_source -c ./start.sh -./son-emu-cli compute start -d datacenter2 -n fw -i firewall -c ./start.sh -./son-emu-cli compute start -d long_data_center_name3 -n tsink -i traffic_sink -c ./start.sh +son-emu-cli compute start -d datacenter1 -n tsrc -i traffic_source -c ./start.sh +son-emu-cli compute start -d datacenter2 -n fw -i firewall -c ./start.sh +son-emu-cli compute start -d long_data_center_name3 -n tsink -i traffic_sink -c ./start.sh # setup links in the chain -./son-emu-cli network add -src tsrc -dst fw -./son-emu-cli network add -src fw -dst tsink -./son-emu-cli network add -src tsink -dst tsrc +son-emu-cli network add -src tsrc -dst fw +son-emu-cli network add -src fw -dst tsink +son-emu-cli network add -src tsink -dst tsrc -- 2.17.1 From 4401c2dba93b30ed76d2cbdcf3dd85fd6fc78322 Mon Sep 17 00:00:00 2001 From: peusterm Date: Mon, 7 Mar 2016 13:24:40 +0100 Subject: [PATCH 11/16] added lead dev contacts to README.md like decided in Wp3 call --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 68e5087..fa45bbf 100755 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ # Distributed Cloud Emulator -Contributors: +Lead developers (able to merge pull requests): * Manuel Peuster +* Steven Van Rossem ### Requirements -- 2.17.1 From 3f6daa9928e2c16534febe67d62d798a779a5178 Mon Sep 17 00:00:00 2001 From: peusterm Date: Mon, 7 Mar 2016 13:30:35 +0100 Subject: [PATCH 12/16] Added Apache LICENSE file. --- LICENSE | 202 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..20a5aea --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + \ No newline at end of file -- 2.17.1 From a1a5ed0f026ead6360e3a0ce5599804d009f1f8b Mon Sep 17 00:00:00 2001 From: peusterm Date: Mon, 7 Mar 2016 15:29:20 +0100 Subject: [PATCH 13/16] Bugfix: Missing ryu dependecies. Closes #33. --- ansible/install.yml | 3 +++ setup.py | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/ansible/install.yml b/ansible/install.yml index 23df943..9580f05 100755 --- a/ansible/install.yml +++ b/ansible/install.yml @@ -30,6 +30,9 @@ - name: install networkx pip: name=networkx + - name: install six + pip: name=six + - name: install ryu pip: name=ryu diff --git a/setup.py b/setup.py index dcda018..a3252bf 100644 --- a/setup.py +++ b/setup.py @@ -11,6 +11,15 @@ setup(name='emuvim', packages=find_packages('src'), install_requires=[ 'pyaml', + 'six', + 'zerorpc', + 'tabulate', + 'argparse', + 'networkx', + 'six', + 'ryu', + 'oslo.config', + 'pytest' ], zip_safe=False, entry_points={ -- 2.17.1 From a4edcd73e263c6869eef82e62a641bc2933f4a70 Mon Sep 17 00:00:00 2001 From: peusterm Date: Mon, 7 Mar 2016 15:53:33 +0100 Subject: [PATCH 14/16] Bugfix: We have to ensure to have the latest version of the six package installed to get ryu to work --- ansible/install.yml | 16 ++++++++-------- setup.py | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ansible/install.yml b/ansible/install.yml index 9580f05..dd6ef4c 100755 --- a/ansible/install.yml +++ b/ansible/install.yml @@ -19,25 +19,25 @@ pip: name=setuptools state=latest - name: install zerorpc - pip: name=zerorpc + pip: name=zerorpc state=latest - name: install tabulate - pip: name=tabulate + pip: name=tabulate state=latest - name: install argparse - pip: name=argparse + pip: name=argparse state=latest - name: install networkx - pip: name=networkx + pip: name=networkx state=latest - name: install six - pip: name=six + pip: name=six state=latest - name: install ryu - pip: name=ryu + pip: name=ryu state=latest - name: install oslo.config - pip: name=oslo.config + pip: name=oslo.config state=latest - name: install pytest - pip: name=pytest + pip: name=pytest state=latest diff --git a/setup.py b/setup.py index a3252bf..f134ffe 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ setup(name='emuvim', 'tabulate', 'argparse', 'networkx', - 'six', + 'six>=1.9', 'ryu', 'oslo.config', 'pytest' -- 2.17.1 From 2f22ebc9f777f47ff7c7792960e5169b7cab73f3 Mon Sep 17 00:00:00 2001 From: cgeoffroy Date: Mon, 7 Mar 2016 19:05:47 +0100 Subject: [PATCH 15/16] Creating a Dockerfile for the son-emu CI --- utils/docker/Dockerfile | 13 +++++++++++++ utils/docker/entrypoint.sh | 7 +++++++ 2 files changed, 20 insertions(+) create mode 100644 utils/docker/Dockerfile create mode 100755 utils/docker/entrypoint.sh diff --git a/utils/docker/Dockerfile b/utils/docker/Dockerfile new file mode 100644 index 0000000..7a9999a --- /dev/null +++ b/utils/docker/Dockerfile @@ -0,0 +1,13 @@ +FROM cgeoffroy/dockernet + +WORKDIR /son-emu + +COPY . /son-emu/ + +RUN cd /son-emu/ansible \ + && ansible-playbook install.yml \ + && cd /son-emu \ + && python setup.py install \ + && echo 'Done' + +ENTRYPOINT ["/son-emu/utils/docker/entrypoint.sh"] diff --git a/utils/docker/entrypoint.sh b/utils/docker/entrypoint.sh new file mode 100755 index 0000000..580762f --- /dev/null +++ b/utils/docker/entrypoint.sh @@ -0,0 +1,7 @@ +#! /bin/bash -e +set -x + +#cp /dockernet/util/docker/entrypoint.sh /tmp/x.sh +#cat /tmp/x.sh | awk 'NR==1{print; print "set -x"} NR!=1' > /dockernet/util/docker/entrypoint.sh + +exec /dockernet/util/docker/entrypoint.sh $* -- 2.17.1 From f5a9169c0af28f1be3e878d12c7905562e513c1b Mon Sep 17 00:00:00 2001 From: cgeoffroy Date: Mon, 7 Mar 2016 18:31:58 +0100 Subject: [PATCH 16/16] Creating the test scripts used during CI --- .gitignore | 3 +++ utils/ci/build_01_unit_tests.sh | 13 +++++++++++++ utils/ci/build_02_integration_tests.sh | 4 ++++ utils/ci/junit-xml/.gitkeep | 0 4 files changed, 20 insertions(+) create mode 100755 utils/ci/build_01_unit_tests.sh create mode 100755 utils/ci/build_02_integration_tests.sh create mode 100644 utils/ci/junit-xml/.gitkeep diff --git a/.gitignore b/.gitignore index 6b050ca..fc2456c 100755 --- a/.gitignore +++ b/.gitignore @@ -64,3 +64,6 @@ target/ #Pytest .pytest.restart + +# JUnit xml +utils/ci/junit-xml/*.xml \ No newline at end of file diff --git a/utils/ci/build_01_unit_tests.sh b/utils/ci/build_01_unit_tests.sh new file mode 100755 index 0000000..ab6ece3 --- /dev/null +++ b/utils/ci/build_01_unit_tests.sh @@ -0,0 +1,13 @@ +#! /bin/bash -e +set -x + +# Go to the 'root' directory +SCRIPT_DIR=$(dirname $(readlink -f $0)) +BASE_DIR=$(readlink -f "${SCRIPT_DIR}/../..") +cd ${BASE_DIR} + +# Remove old test output +rm -rf utils/ci/junit-xml/* + +# Launch the unit testing on emuvim +py.test -v --junit-xml=utils/ci/junit-xml/pytest_emuvim.xml src/emuvim diff --git a/utils/ci/build_02_integration_tests.sh b/utils/ci/build_02_integration_tests.sh new file mode 100755 index 0000000..af027e6 --- /dev/null +++ b/utils/ci/build_02_integration_tests.sh @@ -0,0 +1,4 @@ +#! /bin/bash -e +set -x + +son-emu-cli | grep 'Usage' diff --git a/utils/ci/junit-xml/.gitkeep b/utils/ci/junit-xml/.gitkeep new file mode 100644 index 0000000..e69de29 -- 2.17.1