Example #1
0
File: cmdb.py Project: 4i60r/ralph
 def generate_data(self, data):
     # CITypes loaded from fixtures
     ci_type = CIType.objects.get(id=7)
     return {
         'backup_systems': ServiceCatalogFactory.create(
             type=ci_type,
             name='Backup systems',
             uid=10001,
         ),
         'load_balancing': ServiceCatalogFactory.create(
             type=ci_type,
             name='Load balancing',
             uid=10002,
         ),
         'databases': ServiceCatalogFactory.create(
             type=ci_type,
             name='Databases',
             uid=10003,
         ),
         'other': ServiceCatalogFactory.create(
             type=ci_type,
             uid=10004,
             name='Other',
         )
     }
Example #2
0
 def generate_data(self, data):
     # CITypes loaded from fixtures
     ci_type = CIType.objects.get(id=7)
     return {
         'backup_systems':
         ServiceCatalogFactory.create(
             type=ci_type,
             name='Backup systems',
             uid=10001,
         ),
         'load_balancing':
         ServiceCatalogFactory.create(
             type=ci_type,
             name='Load balancing',
             uid=10002,
         ),
         'databases':
         ServiceCatalogFactory.create(
             type=ci_type,
             name='Databases',
             uid=10003,
         ),
         'other':
         ServiceCatalogFactory.create(
             type=ci_type,
             uid=10004,
             name='Other',
         )
     }
Example #3
0
    def test_change_service_state(self):
        """Change Service state from active to another state when Service have
        connected Devices"""
        data = json.dumps({'state': CI_STATE_TYPES.INACTIVE.id})
        service = ServiceCatalogFactory(state=CI_STATE_TYPES.ACTIVE.id)
        device = DeviceFactory(service=service)

        response = self.patch(
            '/api/v0.9/ci/{}/'.format(service.id),
            data,
            CONTENT_TYPE='application/json',
        )
        self.assertEqual(
            json.loads(response.content)['ci']['state'],
            'You can not change state because this service has linked devices.',
        )

        device.service = None
        device.save()

        response = self.patch(
            '/api/v0.9/ci/{}/'.format(service.id),
            data,
            CONTENT_TYPE='application/json',
        )
        chenged_service = CI.objects.get(id=service.id)
        self.assertEqual(chenged_service.state, CI_STATE_TYPES.INACTIVE.id)
    def test_change_service_state(self):
        """Change Service state from active to another state when Service have
        connected Devices"""

        service = ServiceCatalogFactory(state=CI_STATE_TYPES.ACTIVE.id)
        device = DeviceFactory(service=service)
        data = {
            'base-state': CI_STATE_TYPES.INACTIVE.id,
            'base-status': service.status,
            'base-layers': 1,
            'base-name': service.name,
            'base-type': CI_TYPES.SERVICE.id,
        }

        url = reverse('ci_edit', args=(service.id,))
        response = self.client.post(url, data, follow=True)

        msg = response.context['form'].errors['state'][0]
        self.assertTrue('You can not change state to INACTIVE' in msg)

        device.service = None
        device.save()

        url = reverse('ci_edit', args=(service.id,))
        response = self.client.post(url, data, follow=True)
        self.assertEqual(response.context['form'].errors, {})
Example #5
0
    def test_service(self):
        DCAssetFactory(service=ServiceCatalogFactory(name='dc-service.com'))
        DCAssetFactory(service=ServiceCatalogFactory(name='dc-service2.com'))
        BOAssetFactory(service=ServiceCatalogFactory(name='bo-service.com'))
        BOAssetFactory(service=ServiceCatalogFactory(name='bo-service2.com'))

        field_name = 'service'
        self._check_search_result_count([
            # exact check
            (self.testing_urls['dc'], field_name, '"dc-service.com"', 1),
            (self.testing_urls['dc'], field_name, 'fake-dc', 0),
            (self.testing_urls['bo'], field_name, '"bo-service.com"', 1),
            (self.testing_urls['bo'], field_name, 'fake-bo', 0),
            # icontains check
            (self.testing_urls['dc'], field_name, 'dc', 2),
            (self.testing_urls['dc'], field_name, 'dc-service2', 1),
            (self.testing_urls['dc'], field_name, 'none', 0),
            (self.testing_urls['bo'], field_name, 'bo', 2),
            (self.testing_urls['bo'], field_name, 'bo-service2', 1),
            (self.testing_urls['bo'], field_name, 'none', 0),
        ])
Example #6
0
 def test_signal_sent(self):
     with mock_signal_receiver(fields_synced_signal) as rec:
         old_name = self.dev.name
         author = UserFactory()
         old_service = self.dev.service
         service = ServiceCatalogFactory()
         self.dev.service = service
         self.dev.save(user=author)
         rec.assert_called_with(
             signal=mock.ANY,
             sender=self.dev,
             changes=[ChangeTuple('service', old_service, service)],
             change_author=author,
         )
 def setUp(self):
     self.client = login_as_su()
     self.device_environment = DeviceEnvironmentFactory(name='testenv')
     self.service = ServiceCatalogFactory(name='testservice')
     self.preboot = PrebootFactory(name="prebotname")
     self.ethernet = EthernetFactory.create(mac="0025b0000000", )
     self.network = NetworkFactory.create(
         address='10.80.80.0/20',
         name='testnetwork',
     )
     self.network.save()
     self.venture_role = VentureRoleFactory(name="testventurerole",
                                            venture__symbol='testventure',
                                            venture__name='testventure')
Example #8
0
 def setUp(self):
     venture_role = VentureRoleFactory()
     device_environment = DeviceEnvironmentFactory()
     service = ServiceCatalogFactory()
     self.mass_deployment = MassDeploymentFactory()
     self.user = UserFactory()
     self.data = {
         "mac": "00:00:00:00:00:00",
         "ip": "192.168.1.1",
         "hostname": "testhost.dc2",
         "preboot": PrebootFactory(),
         "venture": venture_role.venture,
         "venture_role": venture_role,
         "service": service.name,
         "device_environment": device_environment.name,
         "asset_identity": None,
     }
Example #9
0
 def test_getting_environments(self):
     service = ServiceCatalogFactory()
     env = DeviceEnvironmentFactory()
     self.assertEqual(len(service.get_environments()), 0)
     CIRelationFactory(parent=service, child=env)
     self.assertEqual(len(service.get_environments()), 1)
Example #10
0
 def setUp(self):
     self.dev = DeviceFactory(service=ServiceCatalogFactory())
Example #11
0
 def test_getting_environments(self):
     service = ServiceCatalogFactory()
     env = DeviceEnvironmentFactory()
     self.assertEqual(len(service.get_environments()), 0)
     CIRelationFactory(parent=service, child=env)
     self.assertEqual(len(service.get_environments()), 1)