You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by re...@apache.org on 2015/12/07 19:35:06 UTC

[1/8] git commit: updated refs/heads/master to 8757daf

Repository: cloudstack
Updated Branches:
  refs/heads/master 24d06099f -> 8757daf2d


Fix NSX rest client to not reset execution counter after a login


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

Branch: refs/heads/master
Commit: cfe14462a3380c053ad174e0016632e6024e3573
Parents: d248e61
Author: Miguel Ferreira <mi...@me.com>
Authored: Wed Dec 2 14:53:56 2015 +0100
Committer: Miguel Ferreira <mi...@me.com>
Committed: Sat Dec 5 15:52:22 2015 +0100

----------------------------------------------------------------------
 .../main/java/com/cloud/network/nicira/NiciraRestClient.java | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/cfe14462/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraRestClient.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraRestClient.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraRestClient.java
index 6ade3a5..de58a42 100644
--- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraRestClient.java
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraRestClient.java
@@ -90,7 +90,7 @@ public class NiciraRestClient extends BasicRestClient {
         if (HttpStatusCodeHelper.isUnauthorized(statusCode)) {
             return handleUnauthorizedResponse(request, previousStatusCode, response, statusCode);
         } else if (HttpStatusCodeHelper.isSuccess(statusCode)) {
-            return handleSuccessResponse(response);
+            return handleSuccessResponse(request, response);
         } else {
             throw new CloudstackRESTException("Unexpecetd status code: " + statusCode);
         }
@@ -110,8 +110,10 @@ public class NiciraRestClient extends BasicRestClient {
         return execute(request, loginStatusCode);
     }
 
-    private CloseableHttpResponse handleSuccessResponse(final CloseableHttpResponse response) {
-        counter.resetExecutionCounter();
+    private CloseableHttpResponse handleSuccessResponse(final HttpUriRequest request, final CloseableHttpResponse response) {
+        if (!request.getURI().getPath().contains(loginUrl)) {
+            counter.resetExecutionCounter();
+        }
         return response;
     }
 


[8/8] git commit: updated refs/heads/master to 8757daf

Posted by re...@apache.org.
Merge pull request #1178 from miguelaferreira/nsx-livelock

Prevent live-lock in NSX API clientThe NSX api client relies on a sequence of responses to identify the need to authenticate and to follow redirects. In order to avoid live-locks, the NSX API client has a counter that will abort the execution after 5 consecutive requests that do not produce a Success (200) response.
When a NSX controller enters a faulty state it can allow authentication requests but deny any other API call. In such cases the NSX API client will consider the denied request a reason to follow a redirect and will enter into a live-lock (because the actual redirection is not happening).
This PR changes the NSX API client to no reset it's counter on a Success response from an authentication request. That is, the counter is only reset if another type of API call yields a Success response.

In addition, this PR also:
* changes the configuration of the license-maven-plugin to ignore files generated by pmd
* moves the NSX marvin test to a plugins folder
* refactors the NSX marvin test to reduce duplication
* adds an extra test case to the NSX marvin test that checks that NSX tunnels are properly created

* pr/1178:
  Test NSX tunnel in guest network
  Refactor test cases to reduce duplication
  Use logger to print debug messages during test
  Move NSX integrationt test to new plugins folder
  Ignore pmd generated files during license check
  Fix NSX rest client to not reset execution counter after a login
  Add test for NSX plugin that simulates a live lock

Signed-off-by: Remi Bergsma <gi...@remi.nl>


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

Branch: refs/heads/master
Commit: 8757daf2d14266318906d4bf41a1e02fe6fde6c2
Parents: 24d0609 811f254
Author: Remi Bergsma <gi...@remi.nl>
Authored: Mon Dec 7 19:34:19 2015 +0100
Committer: Remi Bergsma <gi...@remi.nl>
Committed: Mon Dec 7 19:34:20 2015 +0100

----------------------------------------------------------------------
 .../cloud/network/nicira/NiciraRestClient.java  |   8 +-
 .../network/nicira/NiciraRestClientTest.java    |  42 ++
 pom.xml                                         |   1 +
 .../plugins/test_nicira_controller.py           | 417 +++++++++++++++++++
 .../integration/smoke/test_nicira_controller.py | 310 --------------
 5 files changed, 465 insertions(+), 313 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8757daf2/pom.xml
----------------------------------------------------------------------


[3/8] git commit: updated refs/heads/master to 8757daf

Posted by re...@apache.org.
Use logger to print debug messages during test


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

Branch: refs/heads/master
Commit: 1e820e3906023ae43dbd3f01d632fbef5bb77430
Parents: bafc231
Author: Miguel Ferreira <mi...@me.com>
Authored: Fri Dec 4 11:46:08 2015 +0100
Committer: Miguel Ferreira <mi...@me.com>
Committed: Sat Dec 5 15:52:23 2015 +0100

----------------------------------------------------------------------
 test/integration/plugins/test_nicira_controller.py | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1e820e39/test/integration/plugins/test_nicira_controller.py
----------------------------------------------------------------------
diff --git a/test/integration/plugins/test_nicira_controller.py b/test/integration/plugins/test_nicira_controller.py
index 229612d..197c3f6 100644
--- a/test/integration/plugins/test_nicira_controller.py
+++ b/test/integration/plugins/test_nicira_controller.py
@@ -31,6 +31,7 @@ from marvin.lib.common import (get_domain, get_zone, get_template)
 from nose.plugins.attrib import attr
 from marvin.codes import (FAILED, PASS)
 import time
+import logging
 
 class TestNiciraContoller(cloudstackTestCase):
 
@@ -128,6 +129,11 @@ class TestNiciraContoller(cloudstackTestCase):
             cls.service_offering
         ]
 
+        cls.logger = logging.getLogger('TestNiciraContoller')
+        cls.stream_handler = logging.StreamHandler()
+        cls.logger.setLevel(logging.DEBUG)
+        cls.logger.addHandler(cls.stream_handler)
+
 
     @classmethod
     def tearDownClass(cls):
@@ -170,7 +176,7 @@ class TestNiciraContoller(cloudstackTestCase):
             if result_count == 0:
                 raise Exception('Nicira controller did not return any Transport Zones')
             elif result_count > 1:
-                self.debug("Nicira controller returned %s Transport Zones, picking first one" % resultCount)
+                self.logger.debug("Nicira controller returned %s Transport Zones, picking first one" % resultCount)
             transport_zone_api_url = list_transport_zone_response['results'][0]['_href']
             r3 = requests.get(
                 "https://%s%s" % (controller_host, transport_zone_api_url),
@@ -239,7 +245,7 @@ class TestNiciraContoller(cloudstackTestCase):
         self.test_cleanup.append(virtual_machine)
 
         list_vm_response = VirtualMachine.list(self.api_client, id=virtual_machine.id)
-        self.debug("Verify listVirtualMachines response for virtual machine: %s" % virtual_machine.id)
+        self.logger.debug("Verify listVirtualMachines response for virtual machine: %s" % virtual_machine.id)
 
         self.assertEqual(isinstance(list_vm_response, list), True, 'Response did not return a valid list')
         self.assertNotEqual(len(list_vm_response), 0, 'List of VMs is empty')
@@ -261,7 +267,7 @@ class TestNiciraContoller(cloudstackTestCase):
             should be created without issues.
         """
         nicira_slave = self.determine_slave_conroller(self.nicira_hosts, self.nicira_master_controller)
-        self.debug("Nicira slave controller is: %s " % nicira_slave)
+        self.logger.debug("Nicira slave controller is: %s " % nicira_slave)
 
         nicira_device = NiciraNvp.add(
             self.api_client,
@@ -299,7 +305,7 @@ class TestNiciraContoller(cloudstackTestCase):
         self.test_cleanup.append(virtual_machine)
 
         list_vm_response = VirtualMachine.list(self.api_client, id=virtual_machine.id)
-        self.debug("Verify listVirtualMachines response for virtual machine: %s" % virtual_machine.id)
+        self.logger.debug("Verify listVirtualMachines response for virtual machine: %s" % virtual_machine.id)
 
         self.assertEqual(isinstance(list_vm_response, list), True, 'Response did not return a valid list')
         self.assertNotEqual(len(list_vm_response), 0, 'List of VMs is empty')


[4/8] git commit: updated refs/heads/master to 8757daf

Posted by re...@apache.org.
Ignore pmd generated files during license check

This has been happening for the NSX and BigSwitch plugins.
The maven build prints something like:
  [WARNING] Unknown file extension: .../plugins/network-elements/nicira-nvp/.pmd
  [WARNING] Missing header in: .../plugins/network-elements/nicira-nvp/.pmdruleset.xml


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

Branch: refs/heads/master
Commit: 86e836196ed3374912da805f598961b3fe9c9033
Parents: cfe1446
Author: Miguel Ferreira <mi...@me.com>
Authored: Wed Dec 2 15:42:38 2015 +0100
Committer: Miguel Ferreira <mi...@me.com>
Committed: Sat Dec 5 15:52:23 2015 +0100

----------------------------------------------------------------------
 pom.xml | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/86e83619/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index de7bf7d..a76b5fe 100644
--- a/pom.xml
+++ b/pom.xml
@@ -605,6 +605,7 @@
               <exclude>.checkstyle</exclude>
               <exclude>.project</exclude>
               <exclude>.classpath</exclude>
+              <exclude>.pmd*</exclude>
             </excludes>
           </configuration>
         </plugin>


[6/8] git commit: updated refs/heads/master to 8757daf

Posted by re...@apache.org.
Refactor test cases to reduce duplication


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

Branch: refs/heads/master
Commit: a633ef811324a8dbf868c85922235c16a08cb1a0
Parents: 1e820e3
Author: Miguel Ferreira <mi...@me.com>
Authored: Fri Dec 4 12:10:55 2015 +0100
Committer: Miguel Ferreira <mi...@me.com>
Committed: Sat Dec 5 17:51:20 2015 +0100

----------------------------------------------------------------------
 .../plugins/test_nicira_controller.py           | 71 +++++++++-----------
 1 file changed, 33 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a633ef81/test/integration/plugins/test_nicira_controller.py
----------------------------------------------------------------------
diff --git a/test/integration/plugins/test_nicira_controller.py b/test/integration/plugins/test_nicira_controller.py
index 197c3f6..dd015c9 100644
--- a/test/integration/plugins/test_nicira_controller.py
+++ b/test/integration/plugins/test_nicira_controller.py
@@ -52,11 +52,13 @@ class TestNiciraContoller(cloudstackTestCase):
             'name':              'NiciraEnabledNetwork',
             'displaytext':       'NiciraEnabledNetwork',
             'guestiptype':       'Isolated',
-            'supportedservices': 'SourceNat,Firewall,PortForwarding,Connectivity',
+            'supportedservices': 'SourceNat,Dhcp,Dns,Firewall,PortForwarding,Connectivity',
             'traffictype':       'GUEST',
             'availability':      'Optional',
             'serviceProviderList': {
                     'SourceNat':      'VirtualRouter',
+                    'Dhcp':           'VirtualRouter',
+                    'Dns':            'VirtualRouter',
                     'Firewall':       'VirtualRouter',
                     'PortForwarding': 'VirtualRouter',
                     'Connectivity':   'NiciraNvp'
@@ -207,18 +209,20 @@ class TestNiciraContoller(cloudstackTestCase):
         else:
             raise Exception("None of the supplied hosts (%s) is a Nicira slave" % hosts)
 
-    @attr(tags = ["advanced", "smoke", "nicira"], required_hardware="true")
-    def test_01_nicira_controller(self):
+
+    def add_nicira_device(self, hostname):
         nicira_device = NiciraNvp.add(
             self.api_client,
             None,
             self.physical_network_id,
-            hostname=self.nicira_master_controller,
+            hostname=hostname,
             username=self.nicira_credentials['username'],
             password=self.nicira_credentials['password'],
             transportzoneuuid=self.transport_zone_uuid)
         self.test_cleanup.append(nicira_device)
 
+
+    def create_guest_network(self):
         network_services = {
             'name'            : 'nicira_enabled_network',
             'displaytext'     : 'nicira_enabled_network',
@@ -232,7 +236,10 @@ class TestNiciraContoller(cloudstackTestCase):
             domainid=self.domain.id,
         )
         self.test_cleanup.append(network)
+        return network
+
 
+    def create_virtual_machine(self, network):
         virtual_machine = VirtualMachine.create(
             self.api_client,
             self.vm_services['small'],
@@ -243,6 +250,24 @@ class TestNiciraContoller(cloudstackTestCase):
             mode=self.vm_services['mode']
         )
         self.test_cleanup.append(virtual_machine)
+        return virtual_machine
+
+
+    def get_routers_for_network(self, network):
+        return list_routers(
+            self.apiclient,
+            account='admin',
+            domainid=self.account.domainid,
+            networkid=network.id
+        )
+
+
+    @attr(tags = ["advanced", "smoke", "nicira"], required_hardware="true")
+    def test_01_nicira_controller(self):
+        self.add_nicira_device(self.nicira_master_controller)
+
+        network         = self.create_guest_network()
+        virtual_machine = self.create_virtual_machine(network)
 
         list_vm_response = VirtualMachine.list(self.api_client, id=virtual_machine.id)
         self.logger.debug("Verify listVirtualMachines response for virtual machine: %s" % virtual_machine.id)
@@ -254,6 +279,7 @@ class TestNiciraContoller(cloudstackTestCase):
         self.assertEqual(vm_response.id, virtual_machine.id, 'Virtual machine in response does not match request')
         self.assertEqual(vm_response.state, 'Running', 'VM is not in Running state')
 
+
     @attr(tags = ["advanced", "smoke", "nicira"], required_hardware="true")
     def test_02_nicira_controller_redirect(self):
         """
@@ -269,40 +295,10 @@ class TestNiciraContoller(cloudstackTestCase):
         nicira_slave = self.determine_slave_conroller(self.nicira_hosts, self.nicira_master_controller)
         self.logger.debug("Nicira slave controller is: %s " % nicira_slave)
 
-        nicira_device = NiciraNvp.add(
-            self.api_client,
-            None,
-            self.physical_network_id,
-            hostname=nicira_slave,
-            username=self.nicira_credentials['username'],
-            password=self.nicira_credentials['password'],
-            transportzoneuuid=self.transport_zone_uuid)
-        self.test_cleanup.append(nicira_device)
+        self.add_nicira_device(nicira_slave)
 
-        network_services = {
-            'name'            : 'nicira_enabled_network',
-            'displaytext'     : 'nicira_enabled_network',
-            'zoneid'          : self.zone.id,
-            'networkoffering' : self.network_offering.id
-        }
-        network = Network.create(
-            self.api_client,
-            network_services,
-            accountid='admin',
-            domainid=self.domain.id,
-        )
-        self.test_cleanup.append(network)
-
-        virtual_machine = VirtualMachine.create(
-            self.api_client,
-            self.vm_services['small'],
-            accountid='admin',
-            domainid=self.domain.id,
-            serviceofferingid=self.service_offering.id,
-            networkids=[network.id],
-            mode=self.vm_services['mode']
-        )
-        self.test_cleanup.append(virtual_machine)
+        network         = self.create_guest_network()
+        virtual_machine = self.create_virtual_machine(network)
 
         list_vm_response = VirtualMachine.list(self.api_client, id=virtual_machine.id)
         self.logger.debug("Verify listVirtualMachines response for virtual machine: %s" % virtual_machine.id)
@@ -313,4 +309,3 @@ class TestNiciraContoller(cloudstackTestCase):
         vm_response = list_vm_response[0]
         self.assertEqual(vm_response.id, virtual_machine.id, 'Virtual machine in response does not match request')
         self.assertEqual(vm_response.state, 'Running', 'VM is not in Running state')
-


[7/8] git commit: updated refs/heads/master to 8757daf

Posted by re...@apache.org.
Test NSX tunnel in guest network


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

Branch: refs/heads/master
Commit: 811f254e4ddcc8de0bc0375f35783eea4e04ef6d
Parents: a633ef8
Author: Miguel Ferreira <mi...@me.com>
Authored: Sat Dec 5 15:51:07 2015 +0100
Committer: Miguel Ferreira <mi...@me.com>
Committed: Sat Dec 5 17:51:26 2015 +0100

----------------------------------------------------------------------
 .../plugins/test_nicira_controller.py           | 112 ++++++++++++++++++-
 1 file changed, 109 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/811f254e/test/integration/plugins/test_nicira_controller.py
----------------------------------------------------------------------
diff --git a/test/integration/plugins/test_nicira_controller.py b/test/integration/plugins/test_nicira_controller.py
index dd015c9..6c625b6 100644
--- a/test/integration/plugins/test_nicira_controller.py
+++ b/test/integration/plugins/test_nicira_controller.py
@@ -24,10 +24,19 @@ from marvin.lib.base import (
     NetworkOffering,
     NiciraNvp,
     ServiceOffering,
+    NATRule,
+    PublicIPAddress,
     Network,
     VirtualMachine
 )
-from marvin.lib.common import (get_domain, get_zone, get_template)
+from marvin.lib.common import (
+    get_domain,
+    get_zone,
+    get_template,
+    list_routers,
+    list_hosts,
+    findSuitableHostForMigration
+)
 from nose.plugins.attrib import attr
 from marvin.codes import (FAILED, PASS)
 import time
@@ -255,13 +264,74 @@ class TestNiciraContoller(cloudstackTestCase):
 
     def get_routers_for_network(self, network):
         return list_routers(
-            self.apiclient,
+            self.api_client,
             account='admin',
-            domainid=self.account.domainid,
+            domainid=self.domain.id,
             networkid=network.id
         )
 
 
+    def get_hosts(self):
+        return list_hosts(
+            self.api_client,
+            account='admin',
+            domainid=self.domain.id
+        )
+
+
+    def get_master_router(self, routers):
+        master = filter(lambda r: r.redundantstate == 'MASTER', routers)
+        self.logger.debug("Found %s master router(s): %s" % (master.size(), master))
+        return master[0]
+
+
+    def distribute_vm_and_routers_by_hosts(self, virtual_machine, routers):
+        if len(routers) > 1:
+            router = self.get_router(routers)
+            self.logger.debug("Master Router VM is %s" % router)
+        else:
+            router = routers[0]
+
+        if router.hostid == virtual_machine.hostid:
+            self.logger.debug("Master Router VM is on the same host as VM")
+            host = findSuitableHostForMigration(self.api_client, router.id)
+            if host is not None:
+                router.migrate(self.api_client, host)
+                self.logger.debug("Migrated Master Router VM to host %s" % host)
+            else:
+                self.fail('No suitable host to migrate Master Router VM to')
+        else:
+            self.logger.debug("Master Router VM is not on the same host as VM: %s, %s" % (router.hostid, virtual_machine.hostid))
+
+
+    def acquire_publicip(self, network):
+        self.logger.debug("Associating public IP for network: %s" % network.name)
+        public_ip = PublicIPAddress.create(
+            self.api_client,
+            accountid='admin',
+            zoneid=self.zone.id,
+            domainid=self.domain.id,
+            networkid=network.id
+        )
+        self.logger.debug("Associated %s with network %s" % (public_ip.ipaddress.ipaddress, network.id))
+        self.test_cleanup.append(public_ip)
+        return public_ip
+
+
+    def create_natrule(self, vm, public_ip, network):
+        self.logger.debug("Creating NAT rule in network for vm with public IP")
+        nat_rule = NATRule.create(
+            self.api_client,
+            vm,
+            self.vm_services['small'],
+            ipaddressid=public_ip.ipaddress.id,
+            openfirewall=True,
+            networkid=network.id
+        )
+        self.test_cleanup.append(nat_rule)
+        return nat_rule
+
+
     @attr(tags = ["advanced", "smoke", "nicira"], required_hardware="true")
     def test_01_nicira_controller(self):
         self.add_nicira_device(self.nicira_master_controller)
@@ -309,3 +379,39 @@ class TestNiciraContoller(cloudstackTestCase):
         vm_response = list_vm_response[0]
         self.assertEqual(vm_response.id, virtual_machine.id, 'Virtual machine in response does not match request')
         self.assertEqual(vm_response.state, 'Running', 'VM is not in Running state')
+
+
+    @attr(tags = ["advanced", "smoke", "nicira"], required_hardware="true")
+    def test_03_nicira_tunnel_guest_network(self):
+        self.add_nicira_device(self.nicira_master_controller)
+        network         = self.create_guest_network()
+        virtual_machine = self.create_virtual_machine(network)
+        public_ip       = self.acquire_publicip(network)
+        nat_rule        = self.create_natrule(virtual_machine, public_ip, network)
+
+        list_vm_response = VirtualMachine.list(self.api_client, id=virtual_machine.id)
+        self.logger.debug("Verify listVirtualMachines response for virtual machine: %s" % virtual_machine.id)
+
+        self.assertEqual(isinstance(list_vm_response, list), True, 'Response did not return a valid list')
+        self.assertNotEqual(len(list_vm_response), 0, 'List of VMs is empty')
+
+        vm_response = list_vm_response[0]
+        self.assertEqual(vm_response.id, virtual_machine.id, 'Virtual machine in response does not match request')
+        self.assertEqual(vm_response.state, 'Running', 'VM is not in Running state')
+
+        routers = self.get_routers_for_network(network)
+
+        self.distribute_vm_and_routers_by_hosts(virtual_machine, routers)
+
+        ssh_command = 'ping -c 3 google.com'
+        result = 'failed'
+        try:
+            self.logger.debug("SSH into VM: %s" % public_ip.ipaddress.ipaddress)
+            ssh = virtual_machine.get_ssh_client(ipaddress=public_ip.ipaddress.ipaddress)
+            self.logger.debug('Ping to google.com from VM')
+            result = str(ssh.execute(ssh_command))
+            self.logger.debug("SSH result: %s; COUNT is ==> %s" % (result, result.count("3 packets received")))
+        except Exception as e:
+            self.fail("SSH Access failed for %s: %s" % (vmObj.get_ip(), e))
+
+        self.assertEqual(result.count('3 packets received'), 1, 'Ping to outside world from VM should be successful')


[2/8] git commit: updated refs/heads/master to 8757daf

Posted by re...@apache.org.
Add test for NSX plugin that simulates a live lock


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

Branch: refs/heads/master
Commit: d248e61a3128fe285a18c9836d1c7d18b5b946e9
Parents: 2093c33
Author: Miguel Ferreira <mi...@me.com>
Authored: Wed Dec 2 14:53:26 2015 +0100
Committer: Miguel Ferreira <mi...@me.com>
Committed: Sat Dec 5 15:52:22 2015 +0100

----------------------------------------------------------------------
 .../network/nicira/NiciraRestClientTest.java    | 42 ++++++++++++++++++++
 1 file changed, 42 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d248e61a/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/nicira/NiciraRestClientTest.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/nicira/NiciraRestClientTest.java b/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/nicira/NiciraRestClientTest.java
index 7fcab80..3c5160c 100644
--- a/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/nicira/NiciraRestClientTest.java
+++ b/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/nicira/NiciraRestClientTest.java
@@ -20,6 +20,7 @@
 package com.cloud.network.nicira;
 
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsString;
 import static org.hamcrest.Matchers.isEmptyOrNullString;
 import static org.hamcrest.Matchers.not;
 import static org.hamcrest.Matchers.notNullValue;
@@ -169,4 +170,45 @@ public class NiciraRestClientTest {
             verifyPrivate(client).invoke("execute", HttpRequestMatcher.eq(loginRequest), eq(401));
         }
     }
+
+    @Test
+    public void testExecuteLiveLockWhenControllerAllowsLoginAndFollowsWithUnauthorizedButDoesNotRediect() throws Exception {
+        when(mockResponse.getStatusLine())
+            .thenReturn(HTTP_401_STATUSLINE)
+            .thenReturn(HTTP_200_STATUSLINE)
+            .thenReturn(HTTP_401_STATUSLINE)
+            .thenReturn(HTTP_200_STATUSLINE)
+            .thenReturn(HTTP_401_STATUSLINE)
+            .thenReturn(HTTP_200_STATUSLINE)
+            .thenReturn(HTTP_401_STATUSLINE)
+            .thenReturn(HTTP_200_STATUSLINE)
+            .thenReturn(HTTP_401_STATUSLINE);
+        when(httpClient.execute(eq(HTTP_HOST), HttpRequestMatcher.eq(request), eq(httpClientContext)))
+            .thenReturn(mockResponse)
+            .thenReturn(mockResponse)
+            .thenReturn(mockResponse)
+            .thenReturn(mockResponse)
+            .thenReturn(mockResponse);
+        when(httpClient.execute(eq(HTTP_HOST), HttpRequestMatcher.eq(loginRequest), eq(httpClientContext)))
+            .thenReturn(mockResponse)
+            .thenReturn(mockResponse)
+            .thenReturn(mockResponse)
+            .thenReturn(mockResponse);
+        final NiciraRestClient client = spy(NiciraRestClient.create()
+            .client(httpClient)
+            .clientContext(httpClientContext)
+            .hostname(LOCALHOST)
+            .username(ADMIN)
+            .password(ADMIN_PASSWORD)
+            .loginUrl(LOGIN_PATH)
+            .executionLimit(2)
+            .build());
+
+        try {
+            client.execute(request);
+            fail("Execution count should have been maxed out");
+        } catch (final CloudstackRESTException e) {
+            assertThat(e.getMessage(), containsString("Reached max executions limit of "));
+        }
+    }
 }


[5/8] git commit: updated refs/heads/master to 8757daf

Posted by re...@apache.org.
Move NSX integrationt test to new plugins folder


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

Branch: refs/heads/master
Commit: bafc2313bb872efa07c01dca2fdff4bec9b8dbb6
Parents: 86e8361
Author: Miguel Ferreira <mi...@me.com>
Authored: Fri Dec 4 11:40:09 2015 +0100
Committer: Miguel Ferreira <mi...@me.com>
Committed: Sat Dec 5 15:52:23 2015 +0100

----------------------------------------------------------------------
 .../plugins/test_nicira_controller.py           | 310 +++++++++++++++++++
 .../integration/smoke/test_nicira_controller.py | 310 -------------------
 2 files changed, 310 insertions(+), 310 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bafc2313/test/integration/plugins/test_nicira_controller.py
----------------------------------------------------------------------
diff --git a/test/integration/plugins/test_nicira_controller.py b/test/integration/plugins/test_nicira_controller.py
new file mode 100644
index 0000000..229612d
--- /dev/null
+++ b/test/integration/plugins/test_nicira_controller.py
@@ -0,0 +1,310 @@
+#!/usr/bin/env python
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+
+import requests
+from marvin.cloudstackTestCase import cloudstackTestCase
+from marvin.lib.utils import cleanup_resources
+from marvin.lib.base import (
+    PhysicalNetwork,
+    NetworkOffering,
+    NiciraNvp,
+    ServiceOffering,
+    Network,
+    VirtualMachine
+)
+from marvin.lib.common import (get_domain, get_zone, get_template)
+from nose.plugins.attrib import attr
+from marvin.codes import (FAILED, PASS)
+import time
+
+class TestNiciraContoller(cloudstackTestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        test_case = super(TestNiciraContoller, cls)
+
+        test_client    = test_case.getClsTestClient()
+        cls.config     = test_case.getClsConfig()
+        cls.api_client = test_client.getApiClient()
+
+        cls.physical_networks = cls.config.zones[0].physical_networks
+        cls.nicira_hosts      = cls.config.niciraNvp.hosts
+
+        cls.physical_network_id = cls.get_nicira_enabled_physical_network_id(cls.physical_networks)
+
+        cls.network_offerring_services = {
+            'name':              'NiciraEnabledNetwork',
+            'displaytext':       'NiciraEnabledNetwork',
+            'guestiptype':       'Isolated',
+            'supportedservices': 'SourceNat,Firewall,PortForwarding,Connectivity',
+            'traffictype':       'GUEST',
+            'availability':      'Optional',
+            'serviceProviderList': {
+                    'SourceNat':      'VirtualRouter',
+                    'Firewall':       'VirtualRouter',
+                    'PortForwarding': 'VirtualRouter',
+                    'Connectivity':   'NiciraNvp'
+            }
+        }
+
+        cls.network_offering = NetworkOffering.create(cls.api_client, cls.network_offerring_services)
+        cls.network_offering.update(cls.api_client, state='Enabled')
+
+        cls.nicira_credentials = {
+            'username': 'admin',
+            'password': 'admin'
+        }
+
+        cls.nicira_master_controller = cls.determine_master_controller(
+            cls.nicira_hosts,
+            cls.nicira_credentials
+        )
+
+        cls.transport_zone_uuid = cls.get_transport_zone_from_controller(
+            cls.nicira_master_controller,
+            cls.nicira_credentials
+        )
+
+        cls.domain = get_domain(cls.api_client)
+        cls.zone   = get_zone(cls.api_client, test_client.getZoneForTests())
+
+        template = get_template(
+            cls.api_client,
+            cls.zone.id
+        )
+        if template == FAILED:
+            raise Exception("get_template() failed to return template with description %s" % cls.services['ostype'])
+
+        cls.vm_services = {
+            'mode': cls.zone.networktype,
+            'small': {
+                'zoneid':      cls.zone.id,
+                'template':    template.id,
+                'displayname': 'testserver',
+                'username':    cls.config.zones[0].pods[0].clusters[0].hosts[0].username,
+                'password':    cls.config.zones[0].pods[0].clusters[0].hosts[0].password,
+                'ssh_port':    22,
+                'hypervisor':  cls.config.zones[0].pods[0].clusters[0].hypervisor,
+                'privateport': 22,
+                'publicport':  22,
+                'protocol':    'TCP',
+            },
+            'service_offerings': {
+                'tiny': {
+                    'name':        'Tiny Instance',
+                    'displaytext': 'Tiny Instance',
+                    'cpunumber':   1,
+                    'cpuspeed':    100,
+                    'memory':      64,
+                }
+            }
+        }
+
+        if cls.zone.localstorageenabled == True:
+            cls.vm_services['service_offerings']['tiny']['storagetype'] = 'local'
+
+        cls.service_offering = ServiceOffering.create(
+            cls.api_client,
+            cls.vm_services['service_offerings']['tiny']
+        )
+
+        cls.cleanup = [
+            cls.network_offering,
+            cls.service_offering
+        ]
+
+
+    @classmethod
+    def tearDownClass(cls):
+        try:
+            cleanup_resources(cls.api_client, reversed(cls.cleanup))
+        except Exception as e:
+            raise Exception("Warning: Exception during class cleanup : %s" % e)
+
+    def setUp(self):
+        self.test_cleanup = []
+
+    def tearDown(self):
+        try:
+            cleanup_resources(self.api_client, reversed(self.test_cleanup))
+        except Exception as e:
+            raise Exception("Warning: Exception during test cleanup : %s" % e)
+
+
+    @classmethod
+    def determine_master_controller(cls, hosts, credentials):
+        for host in hosts:
+            r1 = requests.post("https://%s/ws.v1/login" % host, credentials, verify=False)
+            r2 = requests.get("https://%s/ws.v1/control-cluster/status" % host, verify=False, cookies=r1.cookies)
+            status_code = r2.status_code
+            if status_code == 401:
+                continue
+            elif status_code == 200:
+                return host
+        raise Exception("None of the supplied hosts (%s) is a Nicira controller" % hosts)
+
+
+    @classmethod
+    def get_transport_zone_from_controller(cls, controller_host, credentials):
+        r1 = requests.post("https://%s/ws.v1/login" % controller_host, credentials, verify=False)
+        r2 = requests.get("https://%s/ws.v1/transport-zone" % controller_host, verify=False, cookies=r1.cookies)
+        status_code = r2.status_code
+        if status_code == 200:
+            list_transport_zone_response = r2.json()
+            result_count = list_transport_zone_response['result_count']
+            if result_count == 0:
+                raise Exception('Nicira controller did not return any Transport Zones')
+            elif result_count > 1:
+                self.debug("Nicira controller returned %s Transport Zones, picking first one" % resultCount)
+            transport_zone_api_url = list_transport_zone_response['results'][0]['_href']
+            r3 = requests.get(
+                "https://%s%s" % (controller_host, transport_zone_api_url),
+                verify=False,
+                cookies=r1.cookies
+            )
+            return r3.json()['uuid']
+        else:
+            raise Exception("Unexpected response from Nicira controller. Status code = %s, content = %s" % status_code)
+
+
+    @classmethod
+    def get_nicira_enabled_physical_network_id(cls, physical_networks):
+        nicira_physical_network_name = None
+        for physical_network in physical_networks:
+            for provider in physical_network.providers:
+                if provider.name == 'NiciraNvp':
+                    nicira_physical_network_name = physical_network.name
+        if nicira_physical_network_name is None:
+            raise Exception('Did not find a Nicira enabled physical network in configuration')
+        return PhysicalNetwork.list(cls.api_client, name=nicira_physical_network_name)[0].id
+
+
+    def determine_slave_conroller(self, hosts, master_controller):
+        slaves = [ s for s in hosts if s != master_controller ]
+        if len(slaves) > 0:
+            return slaves[0]
+        else:
+            raise Exception("None of the supplied hosts (%s) is a Nicira slave" % hosts)
+
+    @attr(tags = ["advanced", "smoke", "nicira"], required_hardware="true")
+    def test_01_nicira_controller(self):
+        nicira_device = NiciraNvp.add(
+            self.api_client,
+            None,
+            self.physical_network_id,
+            hostname=self.nicira_master_controller,
+            username=self.nicira_credentials['username'],
+            password=self.nicira_credentials['password'],
+            transportzoneuuid=self.transport_zone_uuid)
+        self.test_cleanup.append(nicira_device)
+
+        network_services = {
+            'name'            : 'nicira_enabled_network',
+            'displaytext'     : 'nicira_enabled_network',
+            'zoneid'          : self.zone.id,
+            'networkoffering' : self.network_offering.id
+        }
+        network = Network.create(
+            self.api_client,
+            network_services,
+            accountid='admin',
+            domainid=self.domain.id,
+        )
+        self.test_cleanup.append(network)
+
+        virtual_machine = VirtualMachine.create(
+            self.api_client,
+            self.vm_services['small'],
+            accountid='admin',
+            domainid=self.domain.id,
+            serviceofferingid=self.service_offering.id,
+            networkids=[network.id],
+            mode=self.vm_services['mode']
+        )
+        self.test_cleanup.append(virtual_machine)
+
+        list_vm_response = VirtualMachine.list(self.api_client, id=virtual_machine.id)
+        self.debug("Verify listVirtualMachines response for virtual machine: %s" % virtual_machine.id)
+
+        self.assertEqual(isinstance(list_vm_response, list), True, 'Response did not return a valid list')
+        self.assertNotEqual(len(list_vm_response), 0, 'List of VMs is empty')
+
+        vm_response = list_vm_response[0]
+        self.assertEqual(vm_response.id, virtual_machine.id, 'Virtual machine in response does not match request')
+        self.assertEqual(vm_response.state, 'Running', 'VM is not in Running state')
+
+    @attr(tags = ["advanced", "smoke", "nicira"], required_hardware="true")
+    def test_02_nicira_controller_redirect(self):
+        """
+            Nicira clusters will redirect clients (in this case ACS) to the master node.
+            This test assumes that a Nicira cluster is present and configured properly, and
+            that it has at least two controller nodes. The test will check that ASC follows
+            redirects by:
+                - adding a Nicira Nvp device that points to one of the cluster's slave controllers,
+                - create a VM in a Nicira backed network
+            If all is well, no matter what controller is specified (slaves or master), the vm (and respective router VM)
+            should be created without issues.
+        """
+        nicira_slave = self.determine_slave_conroller(self.nicira_hosts, self.nicira_master_controller)
+        self.debug("Nicira slave controller is: %s " % nicira_slave)
+
+        nicira_device = NiciraNvp.add(
+            self.api_client,
+            None,
+            self.physical_network_id,
+            hostname=nicira_slave,
+            username=self.nicira_credentials['username'],
+            password=self.nicira_credentials['password'],
+            transportzoneuuid=self.transport_zone_uuid)
+        self.test_cleanup.append(nicira_device)
+
+        network_services = {
+            'name'            : 'nicira_enabled_network',
+            'displaytext'     : 'nicira_enabled_network',
+            'zoneid'          : self.zone.id,
+            'networkoffering' : self.network_offering.id
+        }
+        network = Network.create(
+            self.api_client,
+            network_services,
+            accountid='admin',
+            domainid=self.domain.id,
+        )
+        self.test_cleanup.append(network)
+
+        virtual_machine = VirtualMachine.create(
+            self.api_client,
+            self.vm_services['small'],
+            accountid='admin',
+            domainid=self.domain.id,
+            serviceofferingid=self.service_offering.id,
+            networkids=[network.id],
+            mode=self.vm_services['mode']
+        )
+        self.test_cleanup.append(virtual_machine)
+
+        list_vm_response = VirtualMachine.list(self.api_client, id=virtual_machine.id)
+        self.debug("Verify listVirtualMachines response for virtual machine: %s" % virtual_machine.id)
+
+        self.assertEqual(isinstance(list_vm_response, list), True, 'Response did not return a valid list')
+        self.assertNotEqual(len(list_vm_response), 0, 'List of VMs is empty')
+
+        vm_response = list_vm_response[0]
+        self.assertEqual(vm_response.id, virtual_machine.id, 'Virtual machine in response does not match request')
+        self.assertEqual(vm_response.state, 'Running', 'VM is not in Running state')
+

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bafc2313/test/integration/smoke/test_nicira_controller.py
----------------------------------------------------------------------
diff --git a/test/integration/smoke/test_nicira_controller.py b/test/integration/smoke/test_nicira_controller.py
deleted file mode 100644
index 229612d..0000000
--- a/test/integration/smoke/test_nicira_controller.py
+++ /dev/null
@@ -1,310 +0,0 @@
-#!/usr/bin/env python
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you 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.
-
-import requests
-from marvin.cloudstackTestCase import cloudstackTestCase
-from marvin.lib.utils import cleanup_resources
-from marvin.lib.base import (
-    PhysicalNetwork,
-    NetworkOffering,
-    NiciraNvp,
-    ServiceOffering,
-    Network,
-    VirtualMachine
-)
-from marvin.lib.common import (get_domain, get_zone, get_template)
-from nose.plugins.attrib import attr
-from marvin.codes import (FAILED, PASS)
-import time
-
-class TestNiciraContoller(cloudstackTestCase):
-
-    @classmethod
-    def setUpClass(cls):
-        test_case = super(TestNiciraContoller, cls)
-
-        test_client    = test_case.getClsTestClient()
-        cls.config     = test_case.getClsConfig()
-        cls.api_client = test_client.getApiClient()
-
-        cls.physical_networks = cls.config.zones[0].physical_networks
-        cls.nicira_hosts      = cls.config.niciraNvp.hosts
-
-        cls.physical_network_id = cls.get_nicira_enabled_physical_network_id(cls.physical_networks)
-
-        cls.network_offerring_services = {
-            'name':              'NiciraEnabledNetwork',
-            'displaytext':       'NiciraEnabledNetwork',
-            'guestiptype':       'Isolated',
-            'supportedservices': 'SourceNat,Firewall,PortForwarding,Connectivity',
-            'traffictype':       'GUEST',
-            'availability':      'Optional',
-            'serviceProviderList': {
-                    'SourceNat':      'VirtualRouter',
-                    'Firewall':       'VirtualRouter',
-                    'PortForwarding': 'VirtualRouter',
-                    'Connectivity':   'NiciraNvp'
-            }
-        }
-
-        cls.network_offering = NetworkOffering.create(cls.api_client, cls.network_offerring_services)
-        cls.network_offering.update(cls.api_client, state='Enabled')
-
-        cls.nicira_credentials = {
-            'username': 'admin',
-            'password': 'admin'
-        }
-
-        cls.nicira_master_controller = cls.determine_master_controller(
-            cls.nicira_hosts,
-            cls.nicira_credentials
-        )
-
-        cls.transport_zone_uuid = cls.get_transport_zone_from_controller(
-            cls.nicira_master_controller,
-            cls.nicira_credentials
-        )
-
-        cls.domain = get_domain(cls.api_client)
-        cls.zone   = get_zone(cls.api_client, test_client.getZoneForTests())
-
-        template = get_template(
-            cls.api_client,
-            cls.zone.id
-        )
-        if template == FAILED:
-            raise Exception("get_template() failed to return template with description %s" % cls.services['ostype'])
-
-        cls.vm_services = {
-            'mode': cls.zone.networktype,
-            'small': {
-                'zoneid':      cls.zone.id,
-                'template':    template.id,
-                'displayname': 'testserver',
-                'username':    cls.config.zones[0].pods[0].clusters[0].hosts[0].username,
-                'password':    cls.config.zones[0].pods[0].clusters[0].hosts[0].password,
-                'ssh_port':    22,
-                'hypervisor':  cls.config.zones[0].pods[0].clusters[0].hypervisor,
-                'privateport': 22,
-                'publicport':  22,
-                'protocol':    'TCP',
-            },
-            'service_offerings': {
-                'tiny': {
-                    'name':        'Tiny Instance',
-                    'displaytext': 'Tiny Instance',
-                    'cpunumber':   1,
-                    'cpuspeed':    100,
-                    'memory':      64,
-                }
-            }
-        }
-
-        if cls.zone.localstorageenabled == True:
-            cls.vm_services['service_offerings']['tiny']['storagetype'] = 'local'
-
-        cls.service_offering = ServiceOffering.create(
-            cls.api_client,
-            cls.vm_services['service_offerings']['tiny']
-        )
-
-        cls.cleanup = [
-            cls.network_offering,
-            cls.service_offering
-        ]
-
-
-    @classmethod
-    def tearDownClass(cls):
-        try:
-            cleanup_resources(cls.api_client, reversed(cls.cleanup))
-        except Exception as e:
-            raise Exception("Warning: Exception during class cleanup : %s" % e)
-
-    def setUp(self):
-        self.test_cleanup = []
-
-    def tearDown(self):
-        try:
-            cleanup_resources(self.api_client, reversed(self.test_cleanup))
-        except Exception as e:
-            raise Exception("Warning: Exception during test cleanup : %s" % e)
-
-
-    @classmethod
-    def determine_master_controller(cls, hosts, credentials):
-        for host in hosts:
-            r1 = requests.post("https://%s/ws.v1/login" % host, credentials, verify=False)
-            r2 = requests.get("https://%s/ws.v1/control-cluster/status" % host, verify=False, cookies=r1.cookies)
-            status_code = r2.status_code
-            if status_code == 401:
-                continue
-            elif status_code == 200:
-                return host
-        raise Exception("None of the supplied hosts (%s) is a Nicira controller" % hosts)
-
-
-    @classmethod
-    def get_transport_zone_from_controller(cls, controller_host, credentials):
-        r1 = requests.post("https://%s/ws.v1/login" % controller_host, credentials, verify=False)
-        r2 = requests.get("https://%s/ws.v1/transport-zone" % controller_host, verify=False, cookies=r1.cookies)
-        status_code = r2.status_code
-        if status_code == 200:
-            list_transport_zone_response = r2.json()
-            result_count = list_transport_zone_response['result_count']
-            if result_count == 0:
-                raise Exception('Nicira controller did not return any Transport Zones')
-            elif result_count > 1:
-                self.debug("Nicira controller returned %s Transport Zones, picking first one" % resultCount)
-            transport_zone_api_url = list_transport_zone_response['results'][0]['_href']
-            r3 = requests.get(
-                "https://%s%s" % (controller_host, transport_zone_api_url),
-                verify=False,
-                cookies=r1.cookies
-            )
-            return r3.json()['uuid']
-        else:
-            raise Exception("Unexpected response from Nicira controller. Status code = %s, content = %s" % status_code)
-
-
-    @classmethod
-    def get_nicira_enabled_physical_network_id(cls, physical_networks):
-        nicira_physical_network_name = None
-        for physical_network in physical_networks:
-            for provider in physical_network.providers:
-                if provider.name == 'NiciraNvp':
-                    nicira_physical_network_name = physical_network.name
-        if nicira_physical_network_name is None:
-            raise Exception('Did not find a Nicira enabled physical network in configuration')
-        return PhysicalNetwork.list(cls.api_client, name=nicira_physical_network_name)[0].id
-
-
-    def determine_slave_conroller(self, hosts, master_controller):
-        slaves = [ s for s in hosts if s != master_controller ]
-        if len(slaves) > 0:
-            return slaves[0]
-        else:
-            raise Exception("None of the supplied hosts (%s) is a Nicira slave" % hosts)
-
-    @attr(tags = ["advanced", "smoke", "nicira"], required_hardware="true")
-    def test_01_nicira_controller(self):
-        nicira_device = NiciraNvp.add(
-            self.api_client,
-            None,
-            self.physical_network_id,
-            hostname=self.nicira_master_controller,
-            username=self.nicira_credentials['username'],
-            password=self.nicira_credentials['password'],
-            transportzoneuuid=self.transport_zone_uuid)
-        self.test_cleanup.append(nicira_device)
-
-        network_services = {
-            'name'            : 'nicira_enabled_network',
-            'displaytext'     : 'nicira_enabled_network',
-            'zoneid'          : self.zone.id,
-            'networkoffering' : self.network_offering.id
-        }
-        network = Network.create(
-            self.api_client,
-            network_services,
-            accountid='admin',
-            domainid=self.domain.id,
-        )
-        self.test_cleanup.append(network)
-
-        virtual_machine = VirtualMachine.create(
-            self.api_client,
-            self.vm_services['small'],
-            accountid='admin',
-            domainid=self.domain.id,
-            serviceofferingid=self.service_offering.id,
-            networkids=[network.id],
-            mode=self.vm_services['mode']
-        )
-        self.test_cleanup.append(virtual_machine)
-
-        list_vm_response = VirtualMachine.list(self.api_client, id=virtual_machine.id)
-        self.debug("Verify listVirtualMachines response for virtual machine: %s" % virtual_machine.id)
-
-        self.assertEqual(isinstance(list_vm_response, list), True, 'Response did not return a valid list')
-        self.assertNotEqual(len(list_vm_response), 0, 'List of VMs is empty')
-
-        vm_response = list_vm_response[0]
-        self.assertEqual(vm_response.id, virtual_machine.id, 'Virtual machine in response does not match request')
-        self.assertEqual(vm_response.state, 'Running', 'VM is not in Running state')
-
-    @attr(tags = ["advanced", "smoke", "nicira"], required_hardware="true")
-    def test_02_nicira_controller_redirect(self):
-        """
-            Nicira clusters will redirect clients (in this case ACS) to the master node.
-            This test assumes that a Nicira cluster is present and configured properly, and
-            that it has at least two controller nodes. The test will check that ASC follows
-            redirects by:
-                - adding a Nicira Nvp device that points to one of the cluster's slave controllers,
-                - create a VM in a Nicira backed network
-            If all is well, no matter what controller is specified (slaves or master), the vm (and respective router VM)
-            should be created without issues.
-        """
-        nicira_slave = self.determine_slave_conroller(self.nicira_hosts, self.nicira_master_controller)
-        self.debug("Nicira slave controller is: %s " % nicira_slave)
-
-        nicira_device = NiciraNvp.add(
-            self.api_client,
-            None,
-            self.physical_network_id,
-            hostname=nicira_slave,
-            username=self.nicira_credentials['username'],
-            password=self.nicira_credentials['password'],
-            transportzoneuuid=self.transport_zone_uuid)
-        self.test_cleanup.append(nicira_device)
-
-        network_services = {
-            'name'            : 'nicira_enabled_network',
-            'displaytext'     : 'nicira_enabled_network',
-            'zoneid'          : self.zone.id,
-            'networkoffering' : self.network_offering.id
-        }
-        network = Network.create(
-            self.api_client,
-            network_services,
-            accountid='admin',
-            domainid=self.domain.id,
-        )
-        self.test_cleanup.append(network)
-
-        virtual_machine = VirtualMachine.create(
-            self.api_client,
-            self.vm_services['small'],
-            accountid='admin',
-            domainid=self.domain.id,
-            serviceofferingid=self.service_offering.id,
-            networkids=[network.id],
-            mode=self.vm_services['mode']
-        )
-        self.test_cleanup.append(virtual_machine)
-
-        list_vm_response = VirtualMachine.list(self.api_client, id=virtual_machine.id)
-        self.debug("Verify listVirtualMachines response for virtual machine: %s" % virtual_machine.id)
-
-        self.assertEqual(isinstance(list_vm_response, list), True, 'Response did not return a valid list')
-        self.assertNotEqual(len(list_vm_response), 0, 'List of VMs is empty')
-
-        vm_response = list_vm_response[0]
-        self.assertEqual(vm_response.id, virtual_machine.id, 'Virtual machine in response does not match request')
-        self.assertEqual(vm_response.state, 'Running', 'VM is not in Running state')
-