fix unittest issue with docker pull
authorstevenvanrossem <steven.vanrossem@intec.ugent.be>
Fri, 27 Jan 2017 23:52:22 +0000 (00:52 +0100)
committerstevenvanrossem <steven.vanrossem@intec.ugent.be>
Fri, 27 Jan 2017 23:52:22 +0000 (00:52 +0100)
src/emuvim/api/sonata/dummygatekeeper.py
src/emuvim/dcemulator/node.py
src/emuvim/test/api_base.py
src/emuvim/test/base.py

index d5daf42..f9ff506 100755 (executable)
@@ -39,11 +39,12 @@ import hashlib
 import zipfile
 import yaml
 import threading
-from docker import DockerClient
+from docker import DockerClient, APIClient
 from flask import Flask, request
 import flask_restful as fr
 from collections import defaultdict
 import pkg_resources
+from subprocess import Popen
 
 logging.basicConfig()
 LOG = logging.getLogger("sonata-dummy-gatekeeper")
@@ -546,8 +547,18 @@ class Service(object):
                     LOG.debug("Image %r present. Skipping pull." % url)
                     continue
             LOG.info("Pulling image: %r" % url)
-            dc.pull(url,
-                    insecure_registry=True)
+            # this seems to fail with latest docker api version 2.0.2
+            # dc.images.pull(url,
+            #        insecure_registry=True)
+            #using docker cli instead
+            cmd = ["docker",
+                   "pull",
+                   url,
+                   ]
+            Popen(cmd).wait()
+
+
+
 
     def _check_docker_image_exists(self, image_name):
         """
index fd4b8fb..2702bf5 100755 (executable)
@@ -175,13 +175,10 @@ class Datacenter(object):
                 network.append({})
 
         # apply hard-set resource limits=0
-        cpu_percentage = kwargs.get('cpu_percent')
+        cpu_percentage = params.get('cpu_percent')
         if cpu_percentage:
-            cpu_period = self.net.cpu_period
-            cpu_quota = self.net.cpu_period * float(cpu_percentage)
-        else:
-            cpu_quota = None
-            cpu_period = None
+            params['cpu_period'] = self.net.cpu_period
+            params['cpu_quota'] = self.net.cpu_period * float(cpu_percentage)
 
         # create the container
         d = self.net.addDocker(
@@ -190,9 +187,7 @@ class Datacenter(object):
             dcmd=command,
             datacenter=self,
             flavor_name=flavor_name,
-            cpu_period = cpu_period,
-            cpu_quota = cpu_quota,
-            environment = {'VNF_NAME':name}
+            environment = {'VNF_NAME':name},
             **params
         )
 
index 614ecd2..57d4aa5 100755 (executable)
@@ -108,7 +108,7 @@ class SimpleTestTopology(unittest.TestCase):
         Helper to interact with local docker instance.
         """
         if self.docker_cli is None:
-            self.docker_cli = docker.Client(
+            self.docker_cli = docker.APIClient(
                 base_url='unix://var/run/docker.sock')
         return self.docker_cli
 
index 1b06f25..397e2a1 100755 (executable)
@@ -100,7 +100,7 @@ class SimpleTestTopology(unittest.TestCase):
         Helper to interact with local docker instance.
         """
         if self.docker_cli is None:
-            self.docker_cli = docker.Client(
+            self.docker_cli = docker.APIClient(
                 base_url='unix://var/run/docker.sock')
         return self.docker_cli