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')
Beispiel #2
0
 def test_update_object_in_cache(self):
     ipAddress = IpAddress()
     newHost = VmHost()
     InventoryCacheManager.update_object_in_cache('uuid', ipAddress)
     InventoryCacheManager.update_object_in_cache('uuid1', newHost)
     self.mox.ReplayAll()
     eventlet.sleep(2)
     self.mox.VerifyAll()
     self.assertTrue(
         InventoryCacheManager.get_object_from_cache(
             'uuid', Constants.VmHost) is None)
     self.assertTrue(
         InventoryCacheManager.get_object_from_cache(
             'uuid1', Constants.VmHost) is not None)
     self.mox.UnsetStubs()
    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')
    def _create_ip_range_from_xml(self, subnet_id, network_name,
                                  ip_address, start_ip, end_ip):
        lib_utils = XMLUtils()
        net_xml = '<network><name>' + \
            network_name + '</name><forward mode=\'nat\'/><ip address=\' ' + \
            ip_address + \
            '\' netmask=\'255.255.255.0\'><dhcp><range start=\'' + \
            start_ip + '\' end=\'' + end_ip + '\'/>''</dhcp></ip></network>'

        ipRange = IpAddressRange()
        if lib_utils.parseXML(net_xml, '//network/ip/dhcp') is not None:
                startIpAddress = IpAddress()
                startIpAddress.set_address(lib_utils.parseXMLAttributes(
                    net_xml, '//network/ip/dhcp/range', 'start'))
                ipRange.set_id(startIpAddress.get_address())
                startIpAddress.set_id(startIpAddress.get_address())
                startIpAddress.set_allocationType('DHCP')
                ipRange.set_startAddress(startIpAddress)
                endIpAddress = IpAddress()
                endIpAddress.set_address(lib_utils.parseXMLAttributes(
                    net_xml, '//network/ip/dhcp/range', 'end'))
                endIpAddress.set_id(endIpAddress.get_address())
                endIpAddress.set_allocationType('DHCP')
                ipRange.set_endAddress(endIpAddress)
                ipRange.set_allocationType('DHCP')
        else:
                ipRange.set_id(subnet_id + '_AUTO_STATIC')
                ipRange.set_allocationType('AUTO_STATIC')
        return ipRange
    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 _create_ip_range_from_xml(self, subnet_id, network_name,
                                  ip_address, start_ip, end_ip):
        lib_utils = XMLUtils()
        net_xml = '<network><name>' + \
            network_name + '</name><forward mode=\'nat\'/><ip address=\' ' + \
            ip_address + \
            '\' netmask=\'255.255.255.0\'><dhcp><range start=\'' + \
            start_ip + '\' end=\'' + end_ip + '\'/>''</dhcp></ip></network>'

        ipRange = IpAddressRange()
        if lib_utils.parseXML(net_xml, '//network/ip/dhcp') is not None:
                startIpAddress = IpAddress()
                startIpAddress.set_address(lib_utils.parseXMLAttributes(
                    net_xml, '//network/ip/dhcp/range', 'start'))
                ipRange.set_id(startIpAddress.get_address())
                startIpAddress.set_id(startIpAddress.get_address())
                startIpAddress.set_allocationType('DHCP')
                ipRange.set_startAddress(startIpAddress)
                endIpAddress = IpAddress()
                endIpAddress.set_address(lib_utils.parseXMLAttributes(
                    net_xml, '//network/ip/dhcp/range', 'end'))
                endIpAddress.set_id(endIpAddress.get_address())
                endIpAddress.set_allocationType('DHCP')
                ipRange.set_endAddress(endIpAddress)
                ipRange.set_allocationType('DHCP')
        else:
                ipRange.set_id(subnet_id + '_AUTO_STATIC')
                ipRange.set_allocationType('AUTO_STATIC')
        return ipRange