Пример #1
0
class EthernetTest(RalphTestCase):
    def setUp(self):
        self.ip1 = IPAddressFactory()
        self.eth1 = EthernetFactory()

    def test_clear_mac_address_without_ip_should_pass(self):
        self.eth1.mac = None
        self.eth1.clean()
        self.eth1.save()

    def test_clear_mac_address_with_ip_without_dhcp_exposition_should_pass(
            self):  # noqa
        self.ip1.ethernet.mac = None
        self.ip1.ethernet.clean()
        self.ip1.ethernet.save()

    def test_clear_mac_address_with_ip_with_dhcp_exposition_should_not_pass(
            self):  # noqa
        self.ip1.dhcp_expose = True
        self.ip1.save()
        self.ip1.ethernet.mac = None
        with self.assertRaises(
                ValidationError,
                msg='MAC cannot be empty if record is exposed in DHCP'):
            self.ip1.ethernet.clean()

    def test_change_mac_address_with_ip_with_dhcp_exposition_should_not_pass(
            self):  # noqa
        self.ip1.dhcp_expose = True
        self.ip1.save()
        self.ip1.ethernet.mac = '11:12:13:14:15:16'
        with self.assertRaises(ValidationError,
                               msg='Cannot change MAC when exposing in DHCP'):
            self.ip1.ethernet.clean()
Пример #2
0
 def setUpClass(cls):
     from ralph.data_center.tests.factories import (
         DataCenterAssetFactory,
         RackFactory,
     )
     super().setUpClass()
     cls.dc_asset = DataCenterAssetFactory(
         hostname='ralph0.allegro.pl',
         service_env__service__name='service',
         service_env__environment__name='test',
         model__name='DL360',
         model__manufacturer__name='Asus',
         model__category__name='ATS',
         rack=RackFactory(
             name='Rack #100',
             server_room__name='Server Room A',
             server_room__data_center__name='DC1',
         ),
         position=1,
         slot_no='1',
         configuration_path__class_name='www',
         configuration_path__module__name='ralph',
     )
     cls.dc_ip = IPAddressFactory(
         base_object=cls.dc_asset,
         ethernet=EthernetFactory(base_object=cls.dc_asset),
     )
     IPAddressFactory(
         base_object=cls.dc_asset,
         ethernet=EthernetFactory(base_object=cls.dc_asset),
         is_management=True,
     )
Пример #3
0
 def test_get_last_modified_should_return_ethernet_modified(self):
     network = NetworkFactory(address='192.168.1.0/24')
     ethernet = EthernetFactory()
     ip = IPAddressFactory(address='192.168.1.2', ethernet=ethernet)
     ethernet.save()
     returned = self.view.get_last_modified(
         Network.objects.filter(id__in=[network.id]))
     self.assertEqual(returned.strftime("%Y-%m-%d %H:%M:%S"),
                      ethernet.modified.strftime("%Y-%m-%d %H:%M:%S"))
Пример #4
0
 def setUp(self):
     super().setUp()
     self.bo_asset = BackOfficeAssetFactory(
         barcode='12345', hostname='host1'
     )
     self.bo_asset.tags.add('tag1')
     self.conf_module_1 = ConfigurationModuleFactory()
     self.conf_module_2 = ConfigurationModuleFactory(
         parent=self.conf_module_1, name='mod1'
     )
     self.conf_class_1 = ConfigurationClassFactory(
         id=999999,
         module=self.conf_module_2, class_name='cls1'
     )
     self.dc_asset = DataCenterAssetFactory(
         barcode='12543', price='9.00',
         service_env__service__name='test-service',
         service_env__service__uid='sc-123',
         service_env__environment__name='prod',
         configuration_path=self.conf_class_1,
     )
     self.dc_asset.tags.add('tag2')
     self.ip = IPAddressFactory(
         ethernet=EthernetFactory(base_object=self.dc_asset)
     )
     self.service = ServiceEnvironmentFactory(service__name='myservice')
Пример #5
0
 def test_change_ethernet_with_dhcp_exposition_should_not_pass(
         self):  # noqa
     eth = EthernetFactory()
     self.ip.dhcp_expose = True
     self.ip.save()
     self.ip.ethernet = eth
     with self.assertRaises(
             ValidationError,
             msg='Cannot change ethernet when exposing in DHCP'):
         self.ip.clean()
Пример #6
0
 def setUp(self):
     self.rack = RackFactory()
     self.asset = DataCenterAssetFactory(rack=self.rack,
                                         position=randint(0, 100))
     self.ethernets = EthernetFactory.create_batch(2,
                                                   base_object=self.asset)
     self.ip = IPAddressFactory(base_object=self.asset,
                                is_management=False,
                                ethernet=self.ethernets[0])
     self.management = IPAddressFactory(base_object=self.asset,
                                        is_management=True,
                                        ethernet=self.ethernets[1])
Пример #7
0
 def test_create_dhcp_entries_through_gui_with_wrong_ethernet(self):
     self._prepare_create_dhcp_entries_transition()
     eth = EthernetFactory().pk
     response = self.gui_client.post(
         reverse(self.transition_url_name,
                 args=(self.instance.id,
                       self.create_dhcp_entries_transition.id)),
         {
             'create_dhcp_entries__ip_or_network': self.net.pk,
             'create_dhcp_entries__ethernet': eth,
         },
     )
     self.assertEqual(response.status_code, 200)
     self.assertIn('create_dhcp_entries__ethernet',
                   response.context_data['form'].errors)
Пример #8
0
 def test_create_dhcp_entries_through_api_with_wrong_ethernet(self):
     self._prepare_create_dhcp_entries_transition()
     eth = EthernetFactory().pk
     response = self.api_client.post(
         reverse('transitions-view',
                 args=(self.create_dhcp_entries_transition.id,
                       self.instance.pk)),
         {
             'ip_or_network': self.net.pk,
             'ethernet': eth,
         },
         format='json',
     )
     self.assertEqual(response.status_code, 400)
     self.assertIn('"{}" is not a valid choice.'.format(eth),
                   response.data['ethernet'])
Пример #9
0
 def setUp(self):
     super().setUp()
     self.hypervisor = DataCenterAssetFactory()
     self.cloud_hypervisor = CloudHostFactory()
     self.cluster = ClusterFactory()
     self.type = VirtualServerType.objects.create(name='XEN')
     self.virtual_server = VirtualServerFullFactory(
         service_env__environment__name='some_env', )
     self.virtual_server.parent.service_env.service.uid = 's-12345'
     self.virtual_server.parent.service_env.service.save()
     self.virtual_server.service_env.service.business_owners = [self.user1]
     self.virtual_server.service_env.service.technical_owners = [self.user2]
     self.virtual_server.service_env.save()
     self.virtual_server2 = VirtualServerFullFactory()
     self.ip = IPAddressFactory(ethernet=EthernetFactory(
         base_object=self.virtual_server2))
Пример #10
0
 def test_queries_number(self):
     for _ in range(0, 10):
         rack = RackFactory()
         for position in range(1, 6):
             model = DataCenterAssetModelFactory(has_parent=True)
             asset = DataCenterAssetFactory(rack=rack,
                                            position=position,
                                            model=model)
             ethernets = EthernetFactory.create_batch(2, base_object=asset)
             IPAddressFactory(base_object=asset,
                              is_management=False,
                              ethernet=ethernets[0])
             IPAddressFactory(base_object=asset,
                              is_management=True,
                              ethernet=ethernets[1])
     with self.assertNumQueries(103):
         DataCenterAssetTextResource().export()
Пример #11
0
 def setUp(self):
     super().setUp()
     self.service_env = ServiceEnvironmentFactory()
     self.model = DataCenterAssetModelFactory()
     self.rack = RackFactory()
     self.dc_asset = DataCenterAssetFullFactory(
         rack=self.rack,
         position=10,
         model=self.model,
         service_env__environment__name='some_env'
     )
     self.dc_asset.service_env.service.business_owners = [self.user1]
     self.dc_asset.service_env.service.technical_owners = [self.user2]
     self.dc_asset.service_env.save()
     self.ip = IPAddressFactory(
         ethernet=EthernetFactory(base_object=self.dc_asset)
     )
     self.dc_asset.tags.add('db', 'test')
     self.dc_asset_2 = DataCenterAssetFullFactory()
Пример #12
0
 def test_replace_ip_through_gui(self):
     self._prepare_replace_ip_transition()
     ethernet = EthernetFactory(base_object=self.instance)
     ipaddress = IPAddressFactory(address='10.20.30.1',
                                  ethernet=ethernet,
                                  hostname='test_hostname')
     network = self.instance._get_available_networks()[0]
     response = self.gui_client.post(reverse(
         self.transition_url_name,
         args=(self.instance.id, self.assign_replace_ip_transition.id)), {
             'replace_ip__ipaddress': ipaddress.id,
             'replace_ip__network': network.id
         },
                                     follow=True)
     self.assertEqual(response.status_code, 200)
     self.assertTrue(
         response.redirect_chain[0][0],
         reverse(self.redirect_url_name, args=(self.instance.id, )))
     ipaddress.refresh_from_db()
     self.assertNotEqual(ipaddress.address, '10.20.30.1')
Пример #13
0
 def setUp(self):
     super().setUp()
     self.ip = IPAddressFactory(dhcp_expose=True)
     self.eth = self.ip.ethernet
     self.eth2 = EthernetFactory()
Пример #14
0
 def setUpClass(cls):
     super().setUpClass()
     cls.net = NetworkFactory(address='127.0.0.0/24')
     cls.eth = EthernetFactory()
Пример #15
0
 def setUp(self):
     super().setUp()
     self.instance = VirtualServerFactory(parent=self.parent)
     self.eth = EthernetFactory(base_object=self.instance,
                                mac='10:20:30:40:50:60')
Пример #16
0
    def setUpClass(cls):
        from ralph.data_center.tests.factories import (
            ClusterFactory,
            DataCenterAssetFactory,
            RackFactory,
        )
        super().setUpClass()
        cls.dc_asset = DataCenterAssetFactory(
            hostname='ralph0.allegro.pl',
            service_env__service__name='service',
            service_env__environment__name='test',
            model__name='DL360',
            model__manufacturer__name='Asus',
            model__category__name='ATS',
            rack=RackFactory(
                name='Rack #100',
                server_room__name='Server Room A',
                server_room__data_center__name='DC1',
            ),
            position=1,
            slot_no='1',
            configuration_path__class_name='www',
            configuration_path__module__name='ralph',
        )
        cls.dc_ip = IPAddressFactory(
            base_object=cls.dc_asset,
            ethernet=EthernetFactory(base_object=cls.dc_asset),
        )
        IPAddressFactory(
            base_object=cls.dc_asset,
            ethernet=EthernetFactory(base_object=cls.dc_asset),
            is_management=True,
        )
        cls.virtual_server = VirtualServerFactory(
            hostname='s000.local',
            configuration_path=ConfigurationClassFactory(
                class_name='worker',
                module__name='auth'
            ),
            service_env__service__name='service',
            service_env__environment__name='prod',
            type__name='Xen',
            parent=DataCenterAssetFactory(
                hostname='parent',
                model__name='DL380p',
                model__manufacturer__name='Brother',
                model__category__name='Database Machine',
                rack=RackFactory(
                    name='Rack #101',
                    server_room__name='Server Room B',
                    server_room__data_center__name='DC2',
                ),
                position=1,
                slot_no='1',
            ),
        )
        # refresh virtual server to get parent as BaseObject, not
        # DataCenterAsset
        cls.vs_ip = IPAddressFactory(
            base_object=cls.virtual_server,
            ethernet=EthernetFactory(base_object=cls.virtual_server),
        )
        cls.virtual_server = VirtualServer.objects.get(
            pk=cls.virtual_server.id
        )

        cluster = ClusterFactory(
            hostname='',
            type__name='Application',
            configuration_path__class_name='www',
            configuration_path__module__name='ralph',
            service_env__service__name='service',
            service_env__environment__name='preprod',
        )
        cls.boc_1 = BaseObjectCluster.objects.create(
            cluster=cluster,
            base_object=DataCenterAssetFactory(
                rack=RackFactory(), position=1,
            )
        )
        cls.boc_2 = BaseObjectCluster.objects.create(
            cluster=cluster,
            base_object=DataCenterAssetFactory(
                rack=RackFactory(
                    server_room__data_center__name='DC2',
                    server_room__name='Server Room B',
                    name='Rack #101',
                ),
                position=1,
            ),
            is_master=True
        )

        cls.cluster = ClusterFactory._meta.model.objects.get(pk=cluster)
        cls.cluster_ip = IPAddressFactory(
            base_object=cls.cluster,
            ethernet=EthernetFactory(base_object=cls.cluster),
        )
Пример #17
0
 def setUp(self):
     self.ip1 = IPAddressFactory()
     self.eth1 = EthernetFactory()
Пример #18
0
 def setUp(self):
     super().setUp()
     self.instance = DataCenterAssetFactory(rack=self.rack)
     self.eth = EthernetFactory(base_object=self.instance,
                                mac='10:20:30:40:50:60')
Пример #19
0
 def test_filter_duplicated_hostnames(self):
     network = NetworkFactory(address='192.168.1.0/24')
     asset = DataCenterAssetFactory()
     ethernet = EthernetFactory(base_object=asset)
     ethernet.save()
     IPAddressFactory(hostname='host1.mydc.net',
                      address='192.168.1.2',
                      ethernet=ethernet,
                      dhcp_expose=True)
     ethernet2 = EthernetFactory()
     ethernet2.save()
     IPAddressFactory(hostname='host1.mydc.net',
                      address='192.168.1.3',
                      ethernet=ethernet2,
                      dhcp_expose=True)
     ethernet3 = EthernetFactory()
     ethernet3.save()
     ip = IPAddressFactory(hostname='host2.mydc.net',
                           address='192.168.1.4',
                           ethernet=ethernet3,
                           dhcp_expose=True)
     entries = self.view._get_dhcp_entries(
         Network.objects.filter(id__in=[network.id]))
     self.assertEqual(DHCPEntry.objects.count(), 3)
     self.assertEqual(len(entries), 1)
     self.assertEqual(entries[0].pk, ip.pk)