You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by an...@apache.org on 2016/10/14 08:45:04 UTC

[1/3] libcloud git commit: modify tests, flake8

Repository: libcloud
Updated Branches:
  refs/heads/trunk 939f065ed -> 35eb2797c


modify tests, flake8


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/f108598a
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/f108598a
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/f108598a

Branch: refs/heads/trunk
Commit: f108598a54edc98337673aaec4280cf64ed5a378
Parents: 0c1808f
Author: Mario Loria <ma...@arroyonetworks.com>
Authored: Thu Oct 13 14:54:09 2016 -0400
Committer: Anthony Shaw <an...@apache.org>
Committed: Fri Oct 14 19:44:40 2016 +1100

----------------------------------------------------------------------
 .../fixtures/rancher/start_container.json       | 109 +++++++++++++++++++
 libcloud/test/container/test_rancher.py         |   6 +
 2 files changed, 115 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/f108598a/libcloud/test/container/fixtures/rancher/start_container.json
----------------------------------------------------------------------
diff --git a/libcloud/test/container/fixtures/rancher/start_container.json b/libcloud/test/container/fixtures/rancher/start_container.json
new file mode 100644
index 0000000..f70ef02
--- /dev/null
+++ b/libcloud/test/container/fixtures/rancher/start_container.json
@@ -0,0 +1,109 @@
+{
+  "id": "1i31",
+  "type": "container",
+  "links": {
+    "self": "http://172.30.0.100:8080/v1/containers/1i31",
+    "account": "http://172.30.0.100:8080/v1/containers/1i31/account",
+    "credentials": "http://172.30.0.100:8080/v1/containers/1i31/credentials",
+    "healthcheckInstanceHostMaps": "http://172.30.0.100:8080/v1/containers/1i31/healthcheckinstancehostmaps",
+    "hosts": "http://172.30.0.100:8080/v1/containers/1i31/hosts",
+    "instanceLabels": "http://172.30.0.100:8080/v1/containers/1i31/instancelabels",
+    "instanceLinks": "http://172.30.0.100:8080/v1/containers/1i31/instancelinks",
+    "instances": "http://172.30.0.100:8080/v1/containers/1i31/instances",
+    "mounts": "http://172.30.0.100:8080/v1/containers/1i31/mounts",
+    "ports": "http://172.30.0.100:8080/v1/containers/1i31/ports",
+    "serviceEvents": "http://172.30.0.100:8080/v1/containers/1i31/serviceevents",
+    "serviceExposeMaps": "http://172.30.0.100:8080/v1/containers/1i31/serviceexposemaps",
+    "services": "http://172.30.0.100:8080/v1/containers/1i31/services",
+    "targetInstanceLinks": "http://172.30.0.100:8080/v1/containers/1i31/targetinstancelinks",
+    "volumes": "http://172.30.0.100:8080/v1/containers/1i31/volumes",
+    "stats": "http://172.30.0.100:8080/v1/containers/1i31/stats",
+    "containerStats": "http://172.30.0.100:8080/v1/containers/1i31/containerstats"
+  },
+  "actions": {
+    "update": "http://172.30.0.100:8080/v1/containers/1i31/?action=update",
+    "error": "http://172.30.0.100:8080/v1/containers/1i31/?action=error",
+    "remove": "http://172.30.0.100:8080/v1/containers/1i31/?action=remove",
+    "start": "http://172.30.0.100:8080/v1/containers/1i31/?action=start",
+    "logs": "http://172.30.0.100:8080/v1/containers/1i31/?action=logs",
+    "setlabels": "http://172.30.0.100:8080/v1/containers/1i31/?action=setlabels"
+  },
+  "name": "newcontainer",
+  "state": "starting",
+  "accountId": "1a5",
+  "blkioDeviceOptions": null,
+  "build": null,
+  "capAdd": null,
+  "capDrop": null,
+  "command": null,
+  "cpuSet": null,
+  "cpuShares": null,
+  "createIndex": null,
+  "created": "2016-10-06T15:55:58Z",
+  "createdTS": 1475769358000,
+  "dataVolumeMounts": {},
+  "dataVolumes": [],
+  "dataVolumesFrom": null,
+  "deploymentUnitUuid": null,
+  "description": null,
+  "devices": null,
+  "dns": [
+    "169.254.169.250"
+  ],
+  "dnsSearch": [
+    "rancher.internal"
+  ],
+  "dockerPorts": [],
+  "domainName": null,
+  "entryPoint": null,
+  "environment": {
+    "STORAGE_TYPE": "file"
+  },
+  "expose": null,
+  "externalId": "ab334bd25d25db7b94fdcead8f5c023b05bed424f56243187aa90f5ef7f07b09",
+  "extraHosts": null,
+  "firstRunning": "2016-10-06T15:56:00Z",
+  "firstRunningTS": 1475769360000,
+  "healthCheck": null,
+  "healthState": null,
+  "hostId": "1h1",
+  "hostname": null,
+  "imageUuid": "docker:rlister/hastebin:latest",
+  "kind": "container",
+  "labels": {
+    "io.rancher.container.uuid": "6d3dcf5f-28b8-4e60-9bf1-618b76a9a805",
+    "io.rancher.container.name": "newcontainer",
+    "io.rancher.container.ip": "10.42.204.104/16"
+  },
+  "logConfig": null,
+  "lxcConf": null,
+  "memory": null,
+  "memorySwap": null,
+  "nativeContainer": false,
+  "networkContainerId": null,
+  "networkMode": "managed",
+  "pidMode": null,
+  "ports": null,
+  "primaryIpAddress": "10.42.204.104",
+  "privileged": false,
+  "publishAllPorts": false,
+  "readOnly": false,
+  "registryCredentialId": null,
+  "removed": null,
+  "requestedHostId": null,
+  "restartPolicy": null,
+  "securityOpt": null,
+  "startCount": 1,
+  "startOnCreate": true,
+  "stdinOpen": false,
+  "systemContainer": null,
+  "transitioning": "yes",
+  "transitioningMessage": null,
+  "transitioningProgress": null,
+  "tty": false,
+  "user": null,
+  "uuid": "6d3dcf5f-28b8-4e60-9bf1-618b76a9a805",
+  "version": "0",
+  "volumeDriver": null,
+  "workingDir": null
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/f108598a/libcloud/test/container/test_rancher.py
----------------------------------------------------------------------
diff --git a/libcloud/test/container/test_rancher.py b/libcloud/test/container/test_rancher.py
index f0a6edb..178e298 100644
--- a/libcloud/test/container/test_rancher.py
+++ b/libcloud/test/container/test_rancher.py
@@ -162,12 +162,14 @@ class RancherContainerDriverTestCase(unittest.TestCase):
         started = container.start()
         self.assertEqual(started.id, "1i31")
         self.assertEqual(started.name, "newcontainer")
+        self.assertEqual(started.extra['state'], "starting")
 
     def test_stop_container(self):
         container = self.driver.get_container("1i31")
         stopped = container.stop()
         self.assertEqual(stopped.id, "1i31")
         self.assertEqual(stopped.name, "newcontainer")
+        self.assertEqual(stopped.extra['state'], "stopping")
 
     def test_ex_search_containers(self):
         containers = self.driver.ex_search_containers({"state": "running"})
@@ -178,6 +180,7 @@ class RancherContainerDriverTestCase(unittest.TestCase):
         destroyed = container.destroy()
         self.assertEqual(destroyed.id, "1i31")
         self.assertEqual(destroyed.name, "newcontainer")
+        self.assertEqual(destroyed.extra['state'], "stopping")
 
 
 class RancherMockHttp(MockHttp):
@@ -244,6 +247,9 @@ class RancherMockHttp(MockHttp):
         elif method == 'DELETE' or '?action=stop' in url:
             return (httplib.OK, self.fixtures.load('stop_container.json'), {},
                     httplib.responses[httplib.OK])
+        elif '?action=start' in url:
+            return (httplib.OK, self.fixtures.load('start_container.json'), {},
+                    httplib.responses[httplib.OK])
         else:
             return (httplib.OK, self.fixtures.load('deploy_container.json'),
                     {}, httplib.responses[httplib.OK])


[3/3] libcloud git commit: fix state handling Closes #905

Posted by an...@apache.org.
fix state handling
Closes #905


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/35eb2797
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/35eb2797
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/35eb2797

Branch: refs/heads/trunk
Commit: 35eb2797c5e5dd9cdb6f35705eb522fe4b2357f5
Parents: f108598
Author: Mario Loria <ma...@arroyonetworks.com>
Authored: Thu Oct 13 15:34:13 2016 -0400
Committer: Anthony Shaw <an...@apache.org>
Committed: Fri Oct 14 19:44:48 2016 +1100

----------------------------------------------------------------------
 libcloud/container/drivers/rancher.py   | 9 ++++++---
 libcloud/test/container/test_rancher.py | 3 +++
 2 files changed, 9 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/35eb2797/libcloud/container/drivers/rancher.py
----------------------------------------------------------------------
diff --git a/libcloud/container/drivers/rancher.py b/libcloud/container/drivers/rancher.py
index 5a213e4..eda0058 100644
--- a/libcloud/container/drivers/rancher.py
+++ b/libcloud/container/drivers/rancher.py
@@ -707,6 +707,11 @@ class RancherContainerDriver(ContainerDriver):
 
         """
         rancher_state = data['state']
+
+        # A Removed container is purged after x amt of time.
+        # Both of these render the container dead (can't be started later)
+        terminate_condition = ["removed", "purged"]
+
         if 'running' in rancher_state:
             state = ContainerState.RUNNING
         elif 'stopped' in rancher_state:
@@ -715,9 +720,7 @@ class RancherContainerDriver(ContainerDriver):
             state = ContainerState.REBOOTING
         elif 'error' in rancher_state:
             state = ContainerState.ERROR
-        elif 'removed' or 'purged' in rancher_state:
-            # A Removed container is purged after x amt of time.
-            # Both of these render the container dead (can't be started later)
+        elif any(x in rancher_state for x in terminate_condition):
             state = ContainerState.TERMINATED
         elif data['transitioning'] == 'yes':
             # Best we can do for current actions

http://git-wip-us.apache.org/repos/asf/libcloud/blob/35eb2797/libcloud/test/container/test_rancher.py
----------------------------------------------------------------------
diff --git a/libcloud/test/container/test_rancher.py b/libcloud/test/container/test_rancher.py
index 178e298..eb23ddf 100644
--- a/libcloud/test/container/test_rancher.py
+++ b/libcloud/test/container/test_rancher.py
@@ -162,6 +162,7 @@ class RancherContainerDriverTestCase(unittest.TestCase):
         started = container.start()
         self.assertEqual(started.id, "1i31")
         self.assertEqual(started.name, "newcontainer")
+        self.assertEqual(started.state, "pending")
         self.assertEqual(started.extra['state'], "starting")
 
     def test_stop_container(self):
@@ -169,6 +170,7 @@ class RancherContainerDriverTestCase(unittest.TestCase):
         stopped = container.stop()
         self.assertEqual(stopped.id, "1i31")
         self.assertEqual(stopped.name, "newcontainer")
+        self.assertEqual(stopped.state, "pending")
         self.assertEqual(stopped.extra['state'], "stopping")
 
     def test_ex_search_containers(self):
@@ -180,6 +182,7 @@ class RancherContainerDriverTestCase(unittest.TestCase):
         destroyed = container.destroy()
         self.assertEqual(destroyed.id, "1i31")
         self.assertEqual(destroyed.name, "newcontainer")
+        self.assertEqual(destroyed.state, "pending")
         self.assertEqual(destroyed.extra['state'], "stopping")
 
 


[2/3] libcloud git commit: return actual action object

Posted by an...@apache.org.
return actual action object


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/0c1808fb
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/0c1808fb
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/0c1808fb

Branch: refs/heads/trunk
Commit: 0c1808fbd2e488b6cf822487eafdef0d2641c0bb
Parents: 939f065
Author: Mario Loria <ma...@arroyonetworks.com>
Authored: Thu Oct 13 14:47:37 2016 -0400
Committer: Anthony Shaw <an...@apache.org>
Committed: Fri Oct 14 19:44:40 2016 +1100

----------------------------------------------------------------------
 libcloud/container/drivers/rancher.py | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/0c1808fb/libcloud/container/drivers/rancher.py
----------------------------------------------------------------------
diff --git a/libcloud/container/drivers/rancher.py b/libcloud/container/drivers/rancher.py
index 745332d..5a213e4 100644
--- a/libcloud/container/drivers/rancher.py
+++ b/libcloud/container/drivers/rancher.py
@@ -577,11 +577,9 @@ class RancherContainerDriver(ContainerDriver):
         """
         result = self.connection.request('%s/containers/%s?action=start' %
                                          (self.baseuri, container.id),
-                                         method='POST')
-        if result.status in VALID_RESPONSE_CODES:
-            return self.get_container(container.id)
-        else:
-            raise RancherException(result.status, 'failed to start container')
+                                         method='POST').object
+
+        return self._to_container(result)
 
     def stop_container(self, container):
         """
@@ -595,11 +593,9 @@ class RancherContainerDriver(ContainerDriver):
         """
         result = self.connection.request('%s/containers/%s?action=stop' %
                                          (self.baseuri, container.id),
-                                         method='POST')
-        if result.status in VALID_RESPONSE_CODES:
-            return self.get_container(container.id)
-        else:
-            raise RancherException(result.status, 'failed to stop container')
+                                         method='POST').object
+
+        return self._to_container(result)
 
     def ex_search_containers(self, search_params):
         """
@@ -632,11 +628,9 @@ class RancherContainerDriver(ContainerDriver):
         :rtype: ``bool``
         """
         result = self.connection.request('%s/containers/%s' % (self.baseuri,
-                                         container.id), method='DELETE')
-        if result.status in VALID_RESPONSE_CODES:
-            return self.get_container(container.id)
-        else:
-            raise RancherException(result.status, 'failed to stop container')
+                                         container.id), method='DELETE').object
+
+        return self._to_container(result)
 
     def _gen_image(self, imageuuid):
         """