def _createCache(self):
     self.mox.StubOutWithMock(api, "vm_host_get_all")
     vmhost = VmHost()
     vmhost.set_id("vmhost1")
     vmhost1 = VmHost()
     vmhost1.set_id("vmhost2")
     vm = Vm()
     vm.set_id("vm1")
     vm.set_powerState(Constants.VM_POWER_STATES[1])
     vm.set_vmHostId("vmhost1")
     vm1 = Vm()
     vm1.set_id("vm2")
     vm1.set_powerState(Constants.VM_POWER_STATES[1])
     vm1.set_vmHostId("vmhost2")
     vmhost.set_virtualMachineIds(["vm1", "vm2"])
     stPool = StorageVolume()
     stPool.set_id("stpool1")
     subNet = Subnet()
     subNet.set_id("net1")
     api.vm_host_get_all(mox.IgnoreArg()).AndReturn([vmhost, vmhost1])
     self.mox.StubOutWithMock(api, "vm_get_all")
     api.vm_get_all(mox.IgnoreArg()).AndReturn([vm, vm1])
     self.mox.StubOutWithMock(api, "storage_volume_get_all")
     api.storage_volume_get_all(mox.IgnoreArg()).AndReturn([stPool])
     self.mox.StubOutWithMock(api, "subnet_get_all")
     api.subnet_get_all(mox.IgnoreArg()).AndReturn([subNet])
 def test_timestamp_columns(self):
     """
         Test the time stamp columns createEpoch, modifiedEpoch
         and deletedEpoch
     """
     subnet = Subnet()
     subnet.set_id('subnet-01')
     # Check for createEpoch
     epoch_before = utils.get_current_epoch_ms()
     healthnmon_db_api.subnet_save(self.admin_context, subnet)
     epoch_after = utils.get_current_epoch_ms()
     subnet_queried = healthnmon_db_api. \
         subnet_get_by_ids(self.admin_context, [subnet.get_id()])[0]
     self.assert_(test_utils.is_timestamp_between(
         epoch_before, epoch_after, subnet_queried.get_createEpoch()))
     # Check for lastModifiedEpoch
     subnet_modified = subnet_queried
     test_utils.unset_timestamp_fields(subnet_modified)
     subnet_modified.set_name('changed_name')
     epoch_before = utils.get_current_epoch_ms()
     healthnmon_db_api.subnet_save(self.admin_context, subnet_modified)
     epoch_after = utils.get_current_epoch_ms()
     subnet_queried = healthnmon_db_api.subnet_get_by_ids(
         self.admin_context, [subnet.get_id()])[0]
     self.assert_(subnet_modified.get_createEpoch() ==
                  subnet_queried.get_createEpoch())
     self.assert_(test_utils.is_timestamp_between(
         epoch_before, epoch_after, subnet_queried.get_lastModifiedEpoch()))
Example #3
0
 def _createCache(self):
     self.mox.StubOutWithMock(api, 'vm_host_get_all')
     vmhost = VmHost()
     vmhost.set_id('vmhost1')
     vmhost1 = VmHost()
     vmhost1.set_id('vmhost2')
     vm = Vm()
     vm.set_id('vm1')
     vm.set_powerState(Constants.VM_POWER_STATES[1])
     vm.set_vmHostId('vmhost1')
     vm1 = Vm()
     vm1.set_id('vm2')
     vm1.set_powerState(Constants.VM_POWER_STATES[1])
     vm1.set_vmHostId('vmhost2')
     vmhost.set_virtualMachineIds(['vm1', 'vm2'])
     stPool = StorageVolume()
     stPool.set_id('stpool1')
     subNet = Subnet()
     subNet.set_id('net1')
     api.vm_host_get_all(mox.IgnoreArg()).AndReturn([vmhost, vmhost1])
     self.mox.StubOutWithMock(api, 'vm_get_all')
     api.vm_get_all(mox.IgnoreArg()).AndReturn([vm, vm1])
     self.mox.StubOutWithMock(api, 'storage_volume_get_all')
     api.storage_volume_get_all(mox.IgnoreArg()).AndReturn([stPool])
     self.mox.StubOutWithMock(api, 'subnet_get_all')
     api.subnet_get_all(mox.IgnoreArg()).AndReturn([subNet])
Example #4
0
 def get_single_subnet(self):
     subnet_list = []
     subnet = Subnet()
     subnet.set_id('subnet-01')
     subnet.set_name('subnet-01')
     subnet_list.append(subnet)
     return subnet_list
Example #5
0
 def __create_subnet(self, **kwargs):
     subnet = Subnet()
     if kwargs is not None:
         for field in kwargs:
             setattr(subnet, field, kwargs[field])
     api.subnet_save(self.admin_context, subnet)
     return subnet
Example #6
0
 def _createCache(self):
     self.mox.StubOutWithMock(api, 'vm_host_get_all')
     vmhost = VmHost()
     vmhost.set_id('vmhost1')
     vm = Vm()
     vm.set_id('vm1')
     stPool = StorageVolume()
     stPool.set_id('stpool1')
     subnet = Subnet()
     subnet.set_id('bridge0')
     api.vm_host_get_all(mox.IgnoreArg()).AndReturn([vmhost])
     self.mox.StubOutWithMock(api, 'vm_get_all')
     api.vm_get_all(mox.IgnoreArg()).AndReturn([vm])
     self.mox.StubOutWithMock(api, 'storage_volume_get_all')
     api.storage_volume_get_all(mox.IgnoreArg()).AndReturn([stPool])
     self.mox.StubOutWithMock(api, 'subnet_get_all')
     api.subnet_get_all(mox.IgnoreArg()).AndReturn([subnet])
Example #7
0
 def _createCache(self):
     self.mox.StubOutWithMock(api, 'vm_host_get_all')
     vmhost = VmHost()
     vmhost.set_id('vmhost1')
     vm = Vm()
     vm.set_id('vm1')
     stPool = StorageVolume()
     stPool.set_id('stpool1')
     subnet = Subnet()
     subnet.set_id('bridge0')
     api.vm_host_get_all(mox.IgnoreArg()).AndReturn([vmhost])
     self.mox.StubOutWithMock(api, 'vm_get_all')
     api.vm_get_all(mox.IgnoreArg()).AndReturn([vm])
     self.mox.StubOutWithMock(api, 'storage_volume_get_all')
     api.storage_volume_get_all(mox.IgnoreArg()).AndReturn([stPool])
     self.mox.StubOutWithMock(api, 'subnet_get_all')
     api.subnet_get_all(mox.IgnoreArg()).AndReturn([subnet])
Example #8
0
 def test_timestamp_columns(self):
     """
         Test the time stamp columns createEpoch, modifiedEpoch
         and deletedEpoch
     """
     subnet = Subnet()
     subnet.set_id('subnet-01')
     # Check for createEpoch
     epoch_before = utils.get_current_epoch_ms()
     healthnmon_db_api.subnet_save(self.admin_context, subnet)
     epoch_after = utils.get_current_epoch_ms()
     subnet_queried = healthnmon_db_api. \
         subnet_get_by_ids(self.admin_context, [subnet.get_id()])[0]
     self.assert_(test_utils.is_timestamp_between(
         epoch_before, epoch_after, subnet_queried.get_createEpoch()))
     # Check for lastModifiedEpoch
     subnet_modified = subnet_queried
     test_utils.unset_timestamp_fields(subnet_modified)
     subnet_modified.set_name('changed_name')
     epoch_before = utils.get_current_epoch_ms()
     healthnmon_db_api.subnet_save(self.admin_context, subnet_modified)
     epoch_after = utils.get_current_epoch_ms()
     subnet_queried = healthnmon_db_api.subnet_get_by_ids(
         self.admin_context, [subnet.get_id()])[0]
     self.assert_(subnet_modified.get_createEpoch() ==
                  subnet_queried.get_createEpoch())
     self.assert_(test_utils.is_timestamp_between(
         epoch_before, epoch_after, subnet_queried.get_lastModifiedEpoch()))
Example #9
0
 def get_single_subnet(self):
     subnet_list = []
     subnet = Subnet()
     subnet.set_id('subnet-01')
     subnet.set_name('subnet-01')
     subnet_list.append(subnet)
     return subnet_list
Example #10
0
    def test_subnet_delete(self):
        subnet = Subnet()
        subnet.set_id('subnet-01')
        subnet.set_name('subnet-01')
        subnet.set_networkAddress('1.1.1.1')
        subnet.set_networkMask('255.255.255.0')
        subnet.add_networkSources('VS_NETWORK')
        subnet.set_ipType('IPV4')
        subnet.set_isPublic(True)
        subnet.set_isShareable(True)
        subnet.add_dnsServers('test-dns01')
        subnet.set_dnsDomain('test_Domain')
        subnet.add_dnsSearchSuffixes('dnsSearchSuffixes')
        subnet.add_defaultGateways('defaultGateways')
        subnet.set_msDomainName('msDomainName')
        subnet.set_msDomainType('WORKGROUP')
        subnet.add_winsServers('winsServers')
        subnet.add_ntpDateServers('ntpDateServers')
        subnet.set_vlanId(1)
        subnet.set_isBootNetwork(True)
        subnet.add_deploymentServices('deploymentServices')
        subnet.add_parentIds('parentIds')
        subnet.add_childIds('childIds')
        subnet.set_isTrunk(True)
        subnet.add_redundancyPeerIds('redundancyPeerIds')
        subnet.set_redundancyMasterId('redundancyMasterId')
        subnet.set_isNativeVlan(False)
        userIp = IpAddress()
        userIp.set_id('10.10.20.1')
        userIp.set_address('10.10.20.1')
        subnet.add_usedIpAddresses(userIp)
        ipRange = self._create_ip_range_from_xml(subnet.get_id(
        ), 'network1', '10.10.10.1', '10.10.10.1', '10.10.10.2')
        subnet.add_ipAddressRanges(ipRange)
        healthnmon_db_api.subnet_save(self.admin_context, subnet)

        subnet2 = Subnet()
        subnet2.set_id('subnet-02')
        subnet2.set_name('subnet-02')
        healthnmon_db_api.subnet_save(self.admin_context, subnet2)

        vSwitch = VirtualSwitch()
        vSwitch.set_id('vs-01')
        vSwitch.set_name('vs-01')
        vSwitch.add_subnetIds('subnet-01')
        vSwitch.add_subnetIds('subnet-02')
        healthnmon_db_api.virtual_switch_save(self.admin_context,
                                              vSwitch)
        healthnmon_db_api.subnet_delete_by_ids(self.admin_context,
                                               [subnet.id])
        subnets = healthnmon_db_api.subnet_get_by_ids(self.admin_context,
                                                      [subnet.id])

        self.assertTrue(subnets is None or len(subnets) == 0,
                        'subnet deleted')
    def test_subnet_save(self):
        subnet = Subnet()
        subnet.set_id('subnet-01')
        subnet.set_name('subnet-01')
        groupIdType = GroupIdType()
        groupIdType.set_id('groupId-01')
        groupIdType.add_networkTypes('MAPPED')
        groupIdType.add_networkTypes('TUNNEL')
        subnet.add_groupIdTypes(groupIdType)
        subnet.set_networkAddress('1.1.1.1')
        subnet.set_networkMask('255.255.255.0')
        subnet.add_networkSources('VS_NETWORK')
        subnet.set_ipType('IPV4')

        subnet.set_isPublic(True)
        subnet.set_isShareable(True)
        subnet.add_dnsServers('test-dns01')
        subnet.set_dnsDomain('test_Domain')
        subnet.add_dnsSearchSuffixes('dnsSearchSuffixes')
        subnet.add_defaultGateways('defaultGateways')
        subnet.set_msDomainName('msDomainName')
        subnet.set_msDomainType('DOMAIN')
        subnet.add_winsServers('winsServers')
        subnet.add_ntpDateServers('ntpDateServers')
        subnet.set_vlanId('1')
        subnet.set_isBootNetwork(True)
        subnet.add_deploymentServices('deploymentServices')
        subnet.add_parentIds('parentIds')
        subnet.add_childIds('childIds')
        subnet.set_isTrunk(True)
        subnet.add_redundancyPeerIds('redundancyPeerIds')
        subnet.set_redundancyMasterId('redundancyMasterId')
        subnet.set_isNativeVlan(False)
        userIp = IpAddress()
        userIp.set_id('10.10.20.1')
        userIp.set_address('10.10.20.1')
        subnet.add_usedIpAddresses(userIp)
        ipRange = self._create_ip_range_from_xml(subnet.get_id(
        ), 'network1', '10.10.10.1', '10.10.10.1', '10.10.10.2')
        subnet.add_ipAddressRanges(ipRange)

        healthnmon_db_api.subnet_save(self.admin_context, subnet)
        subnets = \
            healthnmon_db_api.subnet_get_by_ids(self.admin_context,
                                                ['subnet-01'])
        self.assertFalse(subnets is None,
                         'subnet all returned a none list')
        self.assertTrue(len(subnets) == 1,
                        'subnet all returned invalid number of list')

        indexOfThesubnet = -1
        for subn in subnets:
            if subn.get_id() == subnet.get_id():
                indexOfThesubnet = subnets.index(subn)
                break

        self.assertTrue(subnets[indexOfThesubnet].get_id()
                        == 'subnet-01', 'Subnet id mismatch')
        self.assertTrue(subnets[indexOfThesubnet].get_name()
                        == 'subnet-01', 'Subnet name mismatch')

        groupIdType = subnets[indexOfThesubnet].get_groupIdTypes()[0]
        self.assertTrue(
            groupIdType.get_id() == 'groupId-01', 'Group id mismatch')
        self.assertTrue(groupIdType.get_networkTypes(
        )[0] == 'MAPPED', 'Network Type mismatch')
        self.assertTrue(groupIdType.get_networkTypes(
        )[1] == 'TUNNEL', 'Network Type mismatch')

        self.assertTrue(
            groupIdType.get_id() == 'groupId-01', 'Group id mismatch')
        self.assertTrue(
            groupIdType.get_id() == 'groupId-01', 'Group id mismatch')
        self.assertTrue(subnets[indexOfThesubnet].get_networkAddress(
        ) == '1.1.1.1', 'Network Address mismatch')
        self.assertTrue(subnets[indexOfThesubnet].get_networkMask(
        ) == '255.255.255.0', 'Subnet mask mismatch')
        self.assertTrue(subnets[indexOfThesubnet].get_networkSources(
        )[0] == 'VS_NETWORK', 'Network Sources mismatch')
        self.assertTrue(subnets[indexOfThesubnet].get_ipType()
                        == 'IPV4', 'Ip Type mismatch')
        self.assertTrue(subnets[indexOfThesubnet].get_isPublic(),
                        'Subnet isPublic returned false')
        self.assertTrue(subnets[indexOfThesubnet].get_isShareable(),
                        'Subnet isShareable returned false')
        self.assertTrue(subnets[indexOfThesubnet].get_dnsServers(
        )[0] == 'test-dns01', 'DnsServer mismatch')
        self.assertTrue(subnets[indexOfThesubnet].get_dnsDomain(
        ) == 'test_Domain', 'DnsDomain mismatch')

        self.assertTrue(subnets[indexOfThesubnet].get_dnsSearchSuffixes(
        )[0] == 'dnsSearchSuffixes', 'Subnet isShareable returned false')
        self.assertTrue(subnets[indexOfThesubnet].get_defaultGateways(
        )[0] == 'defaultGateways', 'defaultGateways mismatch')
        self.assertTrue(subnets[indexOfThesubnet].get_msDomainName(
        ) == 'msDomainName', 'msDomainName mismatch')
        self.assertTrue(subnets[indexOfThesubnet].get_msDomainType(
        ) == 'DOMAIN', 'DOMAIN mismatch')

        self.assertTrue(subnets[indexOfThesubnet].get_winsServers(
        )[0] == 'winsServers', 'winsServers mismatch')
        self.assertTrue(subnets[indexOfThesubnet].get_ntpDateServers(
        )[0] == 'ntpDateServers', 'ntpDateServers mismatch')
        self.assertTrue(
            subnets[indexOfThesubnet].get_vlanId() == '1', 'vlanId mismatch')

        self.assertTrue(subnets[indexOfThesubnet].get_isBootNetwork(),
                        'IsbootNetwork returned False')
        self.assertTrue(subnets[indexOfThesubnet].get_deploymentServices(
        )[0] == 'deploymentServices', 'deploymentServices mismatch')

        self.assertTrue(subnets[indexOfThesubnet].get_parentIds(
        )[0] == 'parentIds', 'parentIds mismatch')
        self.assertTrue(subnets[indexOfThesubnet].get_childIds()[0]
                        == 'childIds', 'childIds mismatch')
        self.assertTrue(subnets[indexOfThesubnet].get_isTrunk(),
                        'IsTrunk returned False')

        self.assertTrue(subnets[indexOfThesubnet].get_redundancyPeerIds(
        )[0] == 'redundancyPeerIds', 'redundancyPeerIds mismatch')
        self.assertTrue(subnets[indexOfThesubnet].get_redundancyMasterId(
        ) == 'redundancyMasterId', 'redundancyMasterId mismatch')
        self.assertFalse(subnets[indexOfThesubnet].get_isNativeVlan(),
                         'IsNativePlan should be false')
Example #12
0
    def test_subnet_save(self):
        subnet = Subnet()
        subnet.set_id('subnet-01')
        subnet.set_name('subnet-01')
        groupIdType = GroupIdType()
        groupIdType.set_id('groupId-01')
        groupIdType.add_networkTypes('MAPPED')
        groupIdType.add_networkTypes('TUNNEL')
        subnet.add_groupIdTypes(groupIdType)
        subnet.set_networkAddress('1.1.1.1')
        subnet.set_networkMask('255.255.255.0')
        subnet.add_networkSources('VS_NETWORK')
        subnet.set_ipType('IPV4')

        subnet.set_isPublic(True)
        subnet.set_isShareable(True)
        subnet.add_dnsServers('test-dns01')
        subnet.set_dnsDomain('test_Domain')
        subnet.add_dnsSearchSuffixes('dnsSearchSuffixes')
        subnet.add_defaultGateways('defaultGateways')
        subnet.set_msDomainName('msDomainName')
        subnet.set_msDomainType('DOMAIN')
        subnet.add_winsServers('winsServers')
        subnet.add_ntpDateServers('ntpDateServers')
        subnet.set_vlanId('1')
        subnet.set_isBootNetwork(True)
        subnet.add_deploymentServices('deploymentServices')
        subnet.add_parentIds('parentIds')
        subnet.add_childIds('childIds')
        subnet.set_isTrunk(True)
        subnet.add_redundancyPeerIds('redundancyPeerIds')
        subnet.set_redundancyMasterId('redundancyMasterId')
        subnet.set_isNativeVlan(False)
        userIp = IpAddress()
        userIp.set_id('10.10.20.1')
        userIp.set_address('10.10.20.1')
        subnet.add_usedIpAddresses(userIp)
        ipRange = self._create_ip_range_from_xml(subnet.get_id(
        ), 'network1', '10.10.10.1', '10.10.10.1', '10.10.10.2')
        subnet.add_ipAddressRanges(ipRange)

        healthnmon_db_api.subnet_save(self.admin_context, subnet)
        subnets = \
            healthnmon_db_api.subnet_get_by_ids(self.admin_context,
                                                ['subnet-01'])
        self.assertFalse(subnets is None,
                         'subnet all returned a none list')
        self.assertTrue(len(subnets) == 1,
                        'subnet all returned invalid number of list')

        indexOfThesubnet = -1
        for subn in subnets:
            if subn.get_id() == subnet.get_id():
                indexOfThesubnet = subnets.index(subn)
                break

        self.assertTrue(subnets[indexOfThesubnet].get_id()
                        == 'subnet-01', 'Subnet id mismatch')
        self.assertTrue(subnets[indexOfThesubnet].get_name()
                        == 'subnet-01', 'Subnet name mismatch')

        groupIdType = subnets[indexOfThesubnet].get_groupIdTypes()[0]
        self.assertTrue(
            groupIdType.get_id() == 'groupId-01', 'Group id mismatch')
        self.assertTrue(groupIdType.get_networkTypes(
        )[0] == 'MAPPED', 'Network Type mismatch')
        self.assertTrue(groupIdType.get_networkTypes(
        )[1] == 'TUNNEL', 'Network Type mismatch')

        self.assertTrue(
            groupIdType.get_id() == 'groupId-01', 'Group id mismatch')
        self.assertTrue(
            groupIdType.get_id() == 'groupId-01', 'Group id mismatch')
        self.assertTrue(subnets[indexOfThesubnet].get_networkAddress(
        ) == '1.1.1.1', 'Network Address mismatch')
        self.assertTrue(subnets[indexOfThesubnet].get_networkMask(
        ) == '255.255.255.0', 'Subnet mask mismatch')
        self.assertTrue(subnets[indexOfThesubnet].get_networkSources(
        )[0] == 'VS_NETWORK', 'Network Sources mismatch')
        self.assertTrue(subnets[indexOfThesubnet].get_ipType()
                        == 'IPV4', 'Ip Type mismatch')
        self.assertTrue(subnets[indexOfThesubnet].get_isPublic(),
                        'Subnet isPublic returned false')
        self.assertTrue(subnets[indexOfThesubnet].get_isShareable(),
                        'Subnet isShareable returned false')
        self.assertTrue(subnets[indexOfThesubnet].get_dnsServers(
        )[0] == 'test-dns01', 'DnsServer mismatch')
        self.assertTrue(subnets[indexOfThesubnet].get_dnsDomain(
        ) == 'test_Domain', 'DnsDomain mismatch')

        self.assertTrue(subnets[indexOfThesubnet].get_dnsSearchSuffixes(
        )[0] == 'dnsSearchSuffixes', 'Subnet isShareable returned false')
        self.assertTrue(subnets[indexOfThesubnet].get_defaultGateways(
        )[0] == 'defaultGateways', 'defaultGateways mismatch')
        self.assertTrue(subnets[indexOfThesubnet].get_msDomainName(
        ) == 'msDomainName', 'msDomainName mismatch')
        self.assertTrue(subnets[indexOfThesubnet].get_msDomainType(
        ) == 'DOMAIN', 'DOMAIN mismatch')

        self.assertTrue(subnets[indexOfThesubnet].get_winsServers(
        )[0] == 'winsServers', 'winsServers mismatch')
        self.assertTrue(subnets[indexOfThesubnet].get_ntpDateServers(
        )[0] == 'ntpDateServers', 'ntpDateServers mismatch')
        self.assertTrue(
            subnets[indexOfThesubnet].get_vlanId() == '1', 'vlanId mismatch')

        self.assertTrue(subnets[indexOfThesubnet].get_isBootNetwork(),
                        'IsbootNetwork returned False')
        self.assertTrue(subnets[indexOfThesubnet].get_deploymentServices(
        )[0] == 'deploymentServices', 'deploymentServices mismatch')

        self.assertTrue(subnets[indexOfThesubnet].get_parentIds(
        )[0] == 'parentIds', 'parentIds mismatch')
        self.assertTrue(subnets[indexOfThesubnet].get_childIds()[0]
                        == 'childIds', 'childIds mismatch')
        self.assertTrue(subnets[indexOfThesubnet].get_isTrunk(),
                        'IsTrunk returned False')

        self.assertTrue(subnets[indexOfThesubnet].get_redundancyPeerIds(
        )[0] == 'redundancyPeerIds', 'redundancyPeerIds mismatch')
        self.assertTrue(subnets[indexOfThesubnet].get_redundancyMasterId(
        ) == 'redundancyMasterId', 'redundancyMasterId mismatch')
        self.assertFalse(subnets[indexOfThesubnet].get_isNativeVlan(),
                         'IsNativePlan should be false')
    def test_subnet_delete(self):
        subnet = Subnet()
        subnet.set_id('subnet-01')
        subnet.set_name('subnet-01')
        subnet.set_networkAddress('1.1.1.1')
        subnet.set_networkMask('255.255.255.0')
        subnet.add_networkSources('VS_NETWORK')
        subnet.set_ipType('IPV4')
        subnet.set_isPublic(True)
        subnet.set_isShareable(True)
        subnet.add_dnsServers('test-dns01')
        subnet.set_dnsDomain('test_Domain')
        subnet.add_dnsSearchSuffixes('dnsSearchSuffixes')
        subnet.add_defaultGateways('defaultGateways')
        subnet.set_msDomainName('msDomainName')
        subnet.set_msDomainType('WORKGROUP')
        subnet.add_winsServers('winsServers')
        subnet.add_ntpDateServers('ntpDateServers')
        subnet.set_vlanId(1)
        subnet.set_isBootNetwork(True)
        subnet.add_deploymentServices('deploymentServices')
        subnet.add_parentIds('parentIds')
        subnet.add_childIds('childIds')
        subnet.set_isTrunk(True)
        subnet.add_redundancyPeerIds('redundancyPeerIds')
        subnet.set_redundancyMasterId('redundancyMasterId')
        subnet.set_isNativeVlan(False)
        userIp = IpAddress()
        userIp.set_id('10.10.20.1')
        userIp.set_address('10.10.20.1')
        subnet.add_usedIpAddresses(userIp)
        ipRange = self._create_ip_range_from_xml(subnet.get_id(
        ), 'network1', '10.10.10.1', '10.10.10.1', '10.10.10.2')
        subnet.add_ipAddressRanges(ipRange)
        healthnmon_db_api.subnet_save(self.admin_context, subnet)

        subnet2 = Subnet()
        subnet2.set_id('subnet-02')
        subnet2.set_name('subnet-02')
        healthnmon_db_api.subnet_save(self.admin_context, subnet2)

        vSwitch = VirtualSwitch()
        vSwitch.set_id('vs-01')
        vSwitch.set_name('vs-01')
        vSwitch.add_subnetIds('subnet-01')
        vSwitch.add_subnetIds('subnet-02')
        healthnmon_db_api.virtual_switch_save(self.admin_context,
                                              vSwitch)
        healthnmon_db_api.subnet_delete_by_ids(self.admin_context,
                                               [subnet.id])
        subnets = healthnmon_db_api.subnet_get_by_ids(self.admin_context,
                                                      [subnet.id])

        self.assertTrue(subnets is None or len(subnets) == 0,
                        'subnet deleted')
Example #14
0
 def test_virtual_switch_save_with_subnet(self):
     # Save virtual switch with a port group
     vSwitch = VirtualSwitch()
     vSwitch.set_id('vSwitch-11')
     vSwitch.set_name('vSwitch-11')
     vSwitch.set_resourceManagerId('rmId')
     vSwitch.set_switchType('vSwitch')
     cost1 = Cost()
     cost1.set_value(100)
     cost1.set_units('USD')
     vSwitch.set_cost(cost1)
     portGroup = PortGroup()
     portGroup.set_id('pg-01')
     portGroup.set_name('pg-01')
     portGroup.set_resourceManagerId('rmId')
     portGroup.set_type('portgroup_type')
     portGroup.set_cost(cost1)
     vSwitch.add_portGroups(portGroup)
     api.virtual_switch_save(self.admin_context, vSwitch)
     # Update after adding a port group and subnet
     vSwitch = api.virtual_switch_get_by_ids(self.admin_context,
                                             [vSwitch.id])[0]
     portGroup2 = PortGroup()
     portGroup2.set_id('pg-02')
     portGroup2.set_name('pg-02')
     portGroup2.set_resourceManagerId('rmId')
     portGroup2.set_type('portgroup_type')
     vSwitch.add_portGroups(portGroup2)
     subnet = Subnet()
     subnet.set_id('subnet-02')
     subnet.set_name('subnet-02')
     subnet.set_networkAddress('1.1.1.1')
     api.subnet_save(self.admin_context, subnet)
     vSwitch.add_subnetIds(subnet.id)
     vSwitch.add_networkInterfaces('1')
     api.virtual_switch_save(self.admin_context, vSwitch)
     virtualswitches = \
         api.virtual_switch_get_by_ids(self.admin_context,
                                       [vSwitch.id])
     # Assert the values
     self.assertTrue(
         len(virtualswitches) == 1,
         'Unexpected number of Virtual Switch returned')
     self.assertTrue(virtualswitches[0].get_id() == 'vSwitch-11',
                     'Virtual Switch id mismatch')
     self.assertTrue(virtualswitches[0].get_name() == 'vSwitch-11',
                     'Virtual Switch name mismatch')
     self.assertTrue(virtualswitches[0].get_resourceManagerId() == 'rmId',
                     'Virtual Switch Resource Manager id mismatch')
     self.assertTrue(virtualswitches[0].get_switchType() == 'vSwitch',
                     'Virtual Switch type mismatch')
     cost1 = virtualswitches[0].get_cost()
     self.assertTrue(cost1.get_value() == 100,
                     'VSwitch Cost Value mismatch')
     self.assertTrue(cost1.get_units() == 'USD',
                     'VSwitch Cost units mismatch')
     portGroups = virtualswitches[0].get_portGroups()
     self.assertTrue(
         len(portGroups) == 2, 'All the portgroups have not been saved')
     self.assertTrue(portGroups[0].get_id() == 'pg-01',
                     'VSwitch Port Group id mismatch')
     self.assertTrue(portGroups[0].get_name() == 'pg-01',
                     'VSwitch Port Group Name mismatch')
     self.assertTrue(portGroups[0].get_resourceManagerId() == 'rmId',
                     'VSwitch portgroup Resource Manager id mismatch')
     self.assertTrue(portGroups[0].get_type() == 'portgroup_type',
                     'VSwitch port group type mismatched')
     cost2 = portGroups[0].get_cost()
     self.assertTrue(cost2.get_value() == 100,
                     'PortGroup Cost Value mismatch')
     self.assertTrue(cost2.get_units() == 'USD',
                     'PortGroup Cost units mismatch')
     self.assertTrue(portGroups[1].get_id() == 'pg-02',
                     'VSwitch Port Group id mismatch')
     self.assertTrue(portGroups[1].get_name() == 'pg-02',
                     'VSwitch Port Group Name mismatch')
     self.assertTrue(portGroups[1].get_resourceManagerId() == 'rmId',
                     'VSwitch portgroup Resource Manager id mismatch')
     self.assertTrue(portGroups[1].get_type() == 'portgroup_type',
                     'VSwitch port group type mismatched')
     subnetId = virtualswitches[0].get_subnetIds()
     self.assertTrue(subnetId[0] == 'subnet-02',
                     'Virtual Switch subnet id mismatch')
     self.assertTrue(virtualswitches[0].get_networkInterfaces()[0] == '1',
                     'Virtual Switch network INterfaces mismatch')
 def test_virtual_switch_save_with_subnet(self):
     # Save virtual switch with a port group
     vSwitch = VirtualSwitch()
     vSwitch.set_id('vSwitch-11')
     vSwitch.set_name('vSwitch-11')
     vSwitch.set_resourceManagerId('rmId')
     vSwitch.set_switchType('vSwitch')
     cost1 = Cost()
     cost1.set_value(100)
     cost1.set_units('USD')
     vSwitch.set_cost(cost1)
     portGroup = PortGroup()
     portGroup.set_id('pg-01')
     portGroup.set_name('pg-01')
     portGroup.set_resourceManagerId('rmId')
     portGroup.set_type('portgroup_type')
     portGroup.set_cost(cost1)
     vSwitch.add_portGroups(portGroup)
     api.virtual_switch_save(self.admin_context, vSwitch)
     # Update after adding a port group and subnet
     vSwitch = api.virtual_switch_get_by_ids(self.admin_context,
                                             [vSwitch.id])[0]
     portGroup2 = PortGroup()
     portGroup2.set_id('pg-02')
     portGroup2.set_name('pg-02')
     portGroup2.set_resourceManagerId('rmId')
     portGroup2.set_type('portgroup_type')
     vSwitch.add_portGroups(portGroup2)
     subnet = Subnet()
     subnet.set_id('subnet-02')
     subnet.set_name('subnet-02')
     subnet.set_networkAddress('1.1.1.1')
     api.subnet_save(self.admin_context, subnet)
     vSwitch.add_subnetIds(subnet.id)
     vSwitch.add_networkInterfaces('1')
     api.virtual_switch_save(self.admin_context, vSwitch)
     virtualswitches = \
         api.virtual_switch_get_by_ids(self.admin_context,
                                       [vSwitch.id])
     # Assert the values
     self.assertTrue(len(virtualswitches) == 1,
                     'Unexpected number of Virtual Switch returned')
     self.assertTrue(virtualswitches[0].get_id(
     ) == 'vSwitch-11', 'Virtual Switch id mismatch')
     self.assertTrue(virtualswitches[0].get_name(
     ) == 'vSwitch-11', 'Virtual Switch name mismatch')
     self.assertTrue(virtualswitches[0].get_resourceManagerId(
     ) == 'rmId', 'Virtual Switch Resource Manager id mismatch')
     self.assertTrue(virtualswitches[0].get_switchType(
     ) == 'vSwitch', 'Virtual Switch type mismatch')
     cost1 = virtualswitches[0].get_cost()
     self.assertTrue(
         cost1.get_value() == 100, 'VSwitch Cost Value mismatch')
     self.assertTrue(
         cost1.get_units() == 'USD', 'VSwitch Cost units mismatch')
     portGroups = virtualswitches[0].get_portGroups()
     self.assertTrue(
         len(portGroups) == 2, 'All the portgroups have not been saved')
     self.assertTrue(portGroups[0].get_id(
     ) == 'pg-01', 'VSwitch Port Group id mismatch')
     self.assertTrue(portGroups[0].get_name(
     ) == 'pg-01', 'VSwitch Port Group Name mismatch')
     self.assertTrue(portGroups[0].get_resourceManagerId(
     ) == 'rmId', 'VSwitch portgroup Resource Manager id mismatch')
     self.assertTrue(portGroups[0].get_type(
     ) == 'portgroup_type', 'VSwitch port group type mismatched')
     cost2 = portGroups[0].get_cost()
     self.assertTrue(
         cost2.get_value() == 100, 'PortGroup Cost Value mismatch')
     self.assertTrue(
         cost2.get_units() == 'USD', 'PortGroup Cost units mismatch')
     self.assertTrue(portGroups[1].get_id(
     ) == 'pg-02', 'VSwitch Port Group id mismatch')
     self.assertTrue(portGroups[1].get_name(
     ) == 'pg-02', 'VSwitch Port Group Name mismatch')
     self.assertTrue(portGroups[1].get_resourceManagerId(
     ) == 'rmId', 'VSwitch portgroup Resource Manager id mismatch')
     self.assertTrue(portGroups[1].get_type(
     ) == 'portgroup_type', 'VSwitch port group type mismatched')
     subnetId = virtualswitches[0].get_subnetIds()
     self.assertTrue(
         subnetId[0] == 'subnet-02', 'Virtual Switch subnet id mismatch')
     self.assertTrue(virtualswitches[0].get_networkInterfaces(
     )[0] == '1', 'Virtual Switch network INterfaces mismatch')
 def test_virtual_switch_save_with_subnet(self):
     # Save virtual switch with a port group
     vSwitch = VirtualSwitch()
     vSwitch.set_id("vSwitch-11")
     vSwitch.set_name("vSwitch-11")
     vSwitch.set_resourceManagerId("rmId")
     vSwitch.set_switchType("vSwitch")
     cost1 = Cost()
     cost1.set_value(100)
     cost1.set_units("USD")
     vSwitch.set_cost(cost1)
     portGroup = PortGroup()
     portGroup.set_id("pg-01")
     portGroup.set_name("pg-01")
     portGroup.set_resourceManagerId("rmId")
     portGroup.set_type("portgroup_type")
     portGroup.set_cost(cost1)
     vSwitch.add_portGroups(portGroup)
     api.virtual_switch_save(self.admin_context, vSwitch)
     # Update after adding a port group and subnet
     vSwitch = api.virtual_switch_get_by_ids(self.admin_context, [vSwitch.id])[0]
     portGroup2 = PortGroup()
     portGroup2.set_id("pg-02")
     portGroup2.set_name("pg-02")
     portGroup2.set_resourceManagerId("rmId")
     portGroup2.set_type("portgroup_type")
     vSwitch.add_portGroups(portGroup2)
     subnet = Subnet()
     subnet.set_id("subnet-02")
     subnet.set_name("subnet-02")
     subnet.set_networkAddress("1.1.1.1")
     api.subnet_save(self.admin_context, subnet)
     vSwitch.add_subnetIds(subnet.id)
     vSwitch.add_networkInterfaces("1")
     api.virtual_switch_save(self.admin_context, vSwitch)
     virtualswitches = api.virtual_switch_get_by_ids(self.admin_context, [vSwitch.id])
     # Assert the values
     self.assertTrue(len(virtualswitches) == 1, "Unexpected number of Virtual Switch returned")
     self.assertTrue(virtualswitches[0].get_id() == "vSwitch-11", "Virtual Switch id mismatch")
     self.assertTrue(virtualswitches[0].get_name() == "vSwitch-11", "Virtual Switch name mismatch")
     self.assertTrue(
         virtualswitches[0].get_resourceManagerId() == "rmId", "Virtual Switch Resource Manager id mismatch"
     )
     self.assertTrue(virtualswitches[0].get_switchType() == "vSwitch", "Virtual Switch type mismatch")
     cost1 = virtualswitches[0].get_cost()
     self.assertTrue(cost1.get_value() == 100, "VSwitch Cost Value mismatch")
     self.assertTrue(cost1.get_units() == "USD", "VSwitch Cost units mismatch")
     portGroups = virtualswitches[0].get_portGroups()
     self.assertTrue(len(portGroups) == 2, "All the portgroups have not been saved")
     self.assertTrue(portGroups[0].get_id() == "pg-01", "VSwitch Port Group id mismatch")
     self.assertTrue(portGroups[0].get_name() == "pg-01", "VSwitch Port Group Name mismatch")
     self.assertTrue(
         portGroups[0].get_resourceManagerId() == "rmId", "VSwitch portgroup Resource Manager id mismatch"
     )
     self.assertTrue(portGroups[0].get_type() == "portgroup_type", "VSwitch port group type mismatched")
     cost2 = portGroups[0].get_cost()
     self.assertTrue(cost2.get_value() == 100, "PortGroup Cost Value mismatch")
     self.assertTrue(cost2.get_units() == "USD", "PortGroup Cost units mismatch")
     self.assertTrue(portGroups[1].get_id() == "pg-02", "VSwitch Port Group id mismatch")
     self.assertTrue(portGroups[1].get_name() == "pg-02", "VSwitch Port Group Name mismatch")
     self.assertTrue(
         portGroups[1].get_resourceManagerId() == "rmId", "VSwitch portgroup Resource Manager id mismatch"
     )
     self.assertTrue(portGroups[1].get_type() == "portgroup_type", "VSwitch port group type mismatched")
     subnetId = virtualswitches[0].get_subnetIds()
     self.assertTrue(subnetId[0] == "subnet-02", "Virtual Switch subnet id mismatch")
     self.assertTrue(
         virtualswitches[0].get_networkInterfaces()[0] == "1", "Virtual Switch network INterfaces mismatch"
     )
Example #17
0
 def test_subnet_save_throw_exception(self):
     self.assertRaises(Exception, healthnmon_db_api.subnet_save,
                       self.admin_context, Subnet())