Ejemplo n.º 1
0
    def test_processUpdates(self):
        self.mock.StubOutWithMock(api, 'vm_host_save')
        self.mock.StubOutWithMock(api, 'subnet_delete_by_ids')
        self.mock.StubOutWithMock(api, 'subnet_save')

        api.vm_host_save(mox.IgnoreArg(),
                         mox.IgnoreArg()).MultipleTimes().AndReturn(None)

        api.subnet_delete_by_ids(
            mox.IgnoreArg(),
            mox.IgnoreArg()).MultipleTimes().AndReturn(None)

        api.subnet_save(mox.IgnoreArg(),
                        mox.IgnoreArg()).MultipleTimes().AndReturn(None)

        self.mock.ReplayAll()
        self.assertEquals(self.LibvirtNetwork.processUpdates(), None)
        host = InventoryCacheManager.get_object_from_cache(
            '1', Constants.VmHost)
        self.assertEquals(
            '52:54:00:34:14:AE', host.get_virtualSwitches()[0].get_id())
        self.assertEquals(
            'nat', host.get_virtualSwitches()[0].get_switchType())
        self.assertEquals('default', host.get_virtualSwitches()[0].get_name())

        self.mock.stubs.UnsetAll()
Ejemplo n.º 2
0
    def test_processUpdates(self):
        self.mock.StubOutWithMock(api, 'vm_host_save')
        self.mock.StubOutWithMock(api, 'subnet_delete_by_ids')
        self.mock.StubOutWithMock(api, 'subnet_save')

        api.vm_host_save(mox.IgnoreArg(),
                         mox.IgnoreArg()).MultipleTimes().AndReturn(None)

        api.subnet_delete_by_ids(mox.IgnoreArg(),
                                 mox.IgnoreArg()).MultipleTimes().AndReturn(None)

        api.subnet_save(mox.IgnoreArg(),
                        mox.IgnoreArg()).MultipleTimes().AndReturn(None)

        self.mock.ReplayAll()
        self.assertEquals(self.LibvirtNetwork.processUpdates(), None)
        host = InventoryCacheManager.get_object_from_cache(
            '1', Constants.VmHost)
        self.assertEquals(
            '52:54:00:34:14:AE', host.get_virtualSwitches()[0].get_id())
        self.assertEquals(
            'nat', host.get_virtualSwitches()[0].get_switchType())
        self.assertEquals('default', host.get_virtualSwitches()[0].get_name())

        self.mock.stubs.UnsetAll()
Ejemplo n.º 3
0
 def __create_subnet(self, **kwargs):
     subnet = Subnet()
     if kwargs is not None:
         for field in kwargs:
             setattr(subnet, field, kwargs[field])
     healthnmon_db_api.subnet_save(self.admin_context, subnet)
     return subnet
Ejemplo n.º 4
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()))
Ejemplo n.º 5
0
 def test_subnet_get_all_by_filters_changessince(self):
     # Create Subnets
     subnet_ids = ('SN1', 'SN2', 'SN3')
     subnet_names = ('name1', 'name2', 'name3')
     for i in range(len(subnet_ids)):
         self.__create_subnet(id=subnet_ids[i], name=subnet_names[i])
     created_time = long(time.time() * 1000L)
     # Wait for 1 sec and update second subnet and delete third subnet
     time.sleep(1)
     second_subnet = healthnmon_db_api. \
         subnet_get_by_ids(self.admin_context, [subnet_ids[1]])[0]
     second_subnet.name = 'New name'
     healthnmon_db_api.subnet_save(self.admin_context, second_subnet)
     healthnmon_db_api.subnet_delete_by_ids(
         self.admin_context, [subnet_ids[2]])
     # Query with filter
     expected_updated_ids = [subnet_ids[1], subnet_ids[2]]
     filters = {'changes-since': created_time}
     subnets = healthnmon_db_api. \
         subnet_get_all_by_filters(self.admin_context, filters,
                                   None, None)
     self.assert_(subnets is not None)
     self.assert_(len(subnets) == 2)
     for subnet in subnets:
         self.assert_(subnet is not None)
         self.assert_(subnet.id in expected_updated_ids)
Ejemplo n.º 6
0
 def test_subnet_get_all_by_filters_changessince(self):
     # Create Subnets
     subnet_ids = ('SN1', 'SN2', 'SN3')
     subnet_names = ('name1', 'name2', 'name3')
     for i in range(len(subnet_ids)):
         self.__create_subnet(id=subnet_ids[i], name=subnet_names[i])
     created_time = long(time.time() * 1000L)
     # Wait for 1 sec and update second subnet and delete third subnet
     time.sleep(1)
     second_subnet = healthnmon_db_api. \
         subnet_get_by_ids(self.admin_context, [subnet_ids[1]])[0]
     second_subnet.name = 'New name'
     healthnmon_db_api.subnet_save(self.admin_context, second_subnet)
     healthnmon_db_api.subnet_delete_by_ids(
         self.admin_context, [subnet_ids[2]])
     # Query with filter
     expected_updated_ids = [subnet_ids[1], subnet_ids[2]]
     filters = {'changes-since': created_time}
     subnets = healthnmon_db_api. \
         subnet_get_all_by_filters(self.admin_context, filters,
                                   None, None)
     self.assert_(subnets is not None)
     self.assert_(len(subnets) == 2)
     for subnet in subnets:
         self.assert_(subnet is not None)
         self.assert_(subnet.id in expected_updated_ids)
Ejemplo n.º 7
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
Ejemplo n.º 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()))
Ejemplo n.º 9
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')
Ejemplo n.º 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')
Ejemplo n.º 11
0
    def testProcessNetwork(self):
        self.mock.StubOutWithMock(api, 'subnet_save')

        api.subnet_save(mox.IgnoreArg(),
                        mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mock.ReplayAll()
        self.assertEquals(self.LibvirtNetwork._processVirtualNetwork(
            libvirt.virLibvirtNetwork()),
            None)
        subnet = InventoryCacheManager.get_object_from_cache(
            'Subnet_52:54:00:34:14:AE', Constants.Network)
        self.assertTrue(subnet is not None)
        self.assertFalse(subnet.get_isBootNetwork())
        self.assertEquals('default', subnet.get_name())
        self.mock.stubs.UnsetAll()
Ejemplo n.º 12
0
    def testProcessNetwork(self):
        self.mock.StubOutWithMock(api, 'subnet_save')

        api.subnet_save(mox.IgnoreArg(),
                        mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mock.ReplayAll()
        self.assertEquals(self.LibvirtNetwork._processVirtualNetwork(
            libvirt.virLibvirtNetwork()),
            None)
        subnet = InventoryCacheManager.get_object_from_cache(
            'Subnet_52:54:00:34:14:AE', Constants.Network)
        self.assertTrue(subnet is not None)
        self.assertFalse(subnet.get_isBootNetwork())
        self.assertEquals('default', subnet.get_name())
        self.mock.stubs.UnsetAll()
Ejemplo n.º 13
0
    def test_processUpdatesException(self):
        self.mock.StubOutWithMock(api, 'vm_host_save')
        self.mock.StubOutWithMock(api, 'subnet_delete_by_ids')
        self.mock.StubOutWithMock(api, 'subnet_save')

        api.vm_host_save(mox.IgnoreArg(),
                         mox.IgnoreArg()).MultipleTimes().AndReturn(None)

        api.subnet_delete_by_ids(mox.IgnoreArg(),
                                 mox.IgnoreArg()).MultipleTimes().AndReturn(None)

        api.subnet_save(mox.IgnoreArg(),
                        mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        mock_libvirtNetwork = LibvirtNetwork(self.connection, '1')
        self.mock.StubOutWithMock(
            mock_libvirtNetwork, '_processNetworkDeletes')
        mock_libvirtNetwork._processNetworkDeletes([], [],).AndRaise(Exception)
        self.mock.ReplayAll()
        self.assertEquals(self.LibvirtNetwork.processUpdates(), None)
        self.assertRaises(Exception, LibvirtNetwork)
        self.mock.stubs.UnsetAll()
Ejemplo n.º 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')
Ejemplo n.º 15
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')
Ejemplo n.º 16
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')
Ejemplo n.º 17
0
 def test_subnet_save_none(self):
     self.assertTrue(healthnmon_db_api.subnet_save(
         self.admin_context, None) is None, 'No subnet should be saved')
Ejemplo n.º 18
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"
     )
Ejemplo n.º 19
0
 def test_subnet_save_none(self):
     self.assertTrue(healthnmon_db_api.subnet_save(
         self.admin_context, None) is None, 'No subnet should be saved')
Ejemplo n.º 20
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')