Ver Fonte

Added network property to subnet and updated tests

Nuwan Goonasekera há 7 anos atrás
pai
commit
410010c4bd

+ 4 - 0
cloudbridge/cloud/base/resources.py

@@ -807,6 +807,10 @@ class BaseSubnet(BaseCloudResource, BaseObjectLifeCycleMixin, Subnet):
                 self._provider == other._provider and
                 self.id == other.id)
 
+    @property
+    def network(self):
+        return self._provider.networking.networks.get(self.network_id)
+
     def wait_till_ready(self, timeout=None, interval=None):
         self.wait_for(
             [SubnetState.AVAILABLE],

+ 10 - 0
cloudbridge/cloud/interfaces/resources.py

@@ -1034,6 +1034,16 @@ class Subnet(ObjectLifeCycleMixin, LabeledCloudResource):
         """
         pass
 
+    @abstractproperty
+    def network(self):
+        """
+        The parent network object associated with this this subnet.
+
+        :rtype: ``Network``
+        :return: `Network` object
+        """
+        pass
+
     @abstractproperty
     def zone(self):
         """

+ 8 - 3
test/test_network_service.py

@@ -69,10 +69,15 @@ class CloudNetworkServiceTestCase(ProviderTestBase):
                     net.subnets, [sn],
                     "Network should have exactly one subnet: %s." % sn.id)
 
-                self.assertIn(
+                self.assertEqual(
                     net.id, sn.network_id,
-                    "Network ID %s should be specified in the subnet's network"
-                    " id %s." % (net.id, sn.network_id))
+                    "Network ID %s and subnet's network id %s should be"
+                    " equal." % (net.id, sn.network_id))
+
+                self.assertEqual(
+                    net, sn.network,
+                    "Network obj %s and subnet's parent net obj %s"
+                    " should be equal." % (net, sn.network))
 
                 self.assertEqual(
                     cidr, sn.cidr_block,

+ 1 - 1
test/test_vm_types_service.py

@@ -30,7 +30,7 @@ class CloudVMTypeServiceTestCase(ProviderTestBase):
                 vm_type.vcpus is None or (
                     isinstance(vm_type.vcpus, six.integer_types) and
                     vm_type.vcpus >= 0),
-                "VMType vcpus family be None or a positive integer")
+                "VMType vcpus family must be None or a positive integer")
             self.assertTrue(
                 vm_type.ram is None or vm_type.ram >= 0,
                 "VMType ram must be None or a positive number")