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)
Example #2
0
    def testProcessnetworkDeletes(self):
        self.mock.StubOutWithMock(api, 'subnet_delete_by_ids')

        api.subnet_delete_by_ids(
            mox.IgnoreArg(),
            mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mock.ReplayAll()
#        cachedSwitchList = ['52:54:00:34:14:AC',
#                            '52:54:00:34:14:AB',
#                            '52:54:00:34:14:AE']
#        updatedSwitchList = ['52:54:00:34:14:AE']
        cachedSubnetList = \
            ['Subnet_52:54:00:34:14:AF',
             'Subnet_52:54:00:34:14:AG',
             'Subnet_52:54:00:34:14:AE']
        updatedSubnetList = \
            ['Subnet_52:54:00:34:14:AE']
        self.assertEquals(self.LibvirtNetwork._processNetworkDeletes(
                          cachedSubnetList,
                          updatedSubnetList), None)
        subnet = InventoryCacheManager.get_object_from_cache(
            'Subnet_52:54:00:34:14:AE', Constants.Network)
        self.assertTrue(subnet is not None)
        subnet = InventoryCacheManager.get_object_from_cache(
            'Subnet_52:54:00:34:14:AG', Constants.Network)
        self.assertTrue(subnet is None)
        self.mock.stubs.UnsetAll()
Example #3
0
    def testProcessnetworkDeletes(self):
        self.mock.StubOutWithMock(api, 'subnet_delete_by_ids')

        api.subnet_delete_by_ids(mox.IgnoreArg(),
                                 mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mock.ReplayAll()
#        cachedSwitchList = ['52:54:00:34:14:AC',
#                            '52:54:00:34:14:AB',
#                            '52:54:00:34:14:AE']
#        updatedSwitchList = ['52:54:00:34:14:AE']
        cachedSubnetList = \
            ['Subnet_52:54:00:34:14:AF',
             'Subnet_52:54:00:34:14:AG',
             'Subnet_52:54:00:34:14:AE']
        updatedSubnetList = \
            ['Subnet_52:54:00:34:14:AE']
        self.assertEquals(self.LibvirtNetwork._processNetworkDeletes(
                          cachedSubnetList,
                          updatedSubnetList), None)
        subnet = InventoryCacheManager.get_object_from_cache(
            'Subnet_52:54:00:34:14:AE', Constants.Network)
        self.assertTrue(subnet is not None)
        subnet = InventoryCacheManager.get_object_from_cache(
            'Subnet_52:54:00:34:14:AG', Constants.Network)
        self.assertTrue(subnet is None)
        self.mock.stubs.UnsetAll()
Example #4
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()
Example #5
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()
Example #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)
    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 #8
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')
Example #9
0
    def testProcessNetworkInterface(self):
        self.mock.StubOutWithMock(api, 'subnet_delete_by_ids')

        api.subnet_delete_by_ids(mox.IgnoreArg(),
                                 mox.IgnoreArg()).MultipleTimes().AndReturn(None)
        self.mock.ReplayAll()
        self.assertEquals(self.LibvirtNetwork._processNetworkInterface(
            libvirt.virLibvirtInterfaceEth0()),
            None)
        host = InventoryCacheManager.get_object_from_cache(
            '1', Constants.VmHost)
        self.assertTrue(host.get_ipAddresses is not None)
        self.mock.stubs.UnsetAll()
 def test_subnet_get_all_by_filters_not_deleted(self):
     # Create Subnets
     subnet_ids = ('SN1', 'SN2')
     subnet_names = ('name1', 'name2')
     for i in range(len(subnet_ids)):
         self.__create_subnet(id=subnet_ids[i], name=subnet_names[i])
     # Delete one subnet
     healthnmon_db_api.subnet_delete_by_ids(
         self.admin_context, [subnet_ids[0]])
     # Query with filter
     filters = {'deleted': False}
     subnets = healthnmon_db_api. \
         subnet_get_all_by_filters(self.admin_context, filters,
                                   'id', DbConstants.ORDER_ASC)
     self.assert_(subnets is not None)
     self.assert_(len(subnets) == 1)
     self.assert_(subnets[0] is not None)
     self.assert_(subnets[0].id == subnet_ids[1])
Example #11
0
 def test_subnet_get_all_by_filters_not_deleted(self):
     # Create Subnets
     subnet_ids = ('SN1', 'SN2')
     subnet_names = ('name1', 'name2')
     for i in range(len(subnet_ids)):
         self.__create_subnet(id=subnet_ids[i], name=subnet_names[i])
     # Delete one subnet
     healthnmon_db_api.subnet_delete_by_ids(
         self.admin_context, [subnet_ids[0]])
     # Query with filter
     filters = {'deleted': False}
     subnets = healthnmon_db_api. \
         subnet_get_all_by_filters(self.admin_context, filters,
                                   'id', DbConstants.ORDER_ASC)
     self.assert_(subnets is not None)
     self.assert_(len(subnets) == 1)
     self.assert_(subnets[0] is not None)
     self.assert_(subnets[0].id == subnet_ids[1])
Example #12
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()
 def test_subnet_delete_none(self):
     self.assertTrue(
         healthnmon_db_api.subnet_delete_by_ids(
             self.admin_context,
             None) is None, 'No subnet to be deleted')
Example #14
0
 def test_subnet_delete_none(self):
     self.assertTrue(
         healthnmon_db_api.subnet_delete_by_ids(
             self.admin_context,
             None) is None, 'No subnet to be deleted')