Пример #1
0
    def test_create_ci_generate_change(self):
        # TICKETS REGISTRATION IN THIS TEST IS DISABLED.
        # first case - automatic change
        hostci = CI(name='s11401.dc2', uid='mm-1')
        hostci.type_id = CI_TYPES.DEVICE.id
        hostci.save()
        # not registered, because not user - driven change
        self.assertEqual(
            set([(x.content_object.old_value, x.content_object.new_value,
                  x.content_object.field_name, x.content_object.user_id,
                  x.registration_type) for x in CIChange.objects.all()]),
            set([(u'None', u'Device', u'type', None,
                  CI_CHANGE_REGISTRATION_TYPES.NOT_REGISTERED.id),
                 (u'None', u'1', u'id', None,
                  CI_CHANGE_REGISTRATION_TYPES.NOT_REGISTERED.id)]))
        hostci.delete()
        # second case - manual change
        user = User.objects.create_user('john', '*****@*****.**',
                                        'johnpassword')

        # john reigstered change, change should be at WAITING because
        # registering is not enabled in config
        hostci = CI(name='s11401.dc2', uid='mm-1')
        hostci.type_id = CI_TYPES.DEVICE.id
        hostci.save(user=user)
        self.assertEqual(
            set([(x.content_object.old_value, x.content_object.new_value,
                  x.content_object.field_name, x.content_object.user_id,
                  x.registration_type) for x in CIChange.objects.all()]),
            set([
                (u'None', u'Device', u'type', 1,
                 CI_CHANGE_REGISTRATION_TYPES.WAITING.id),
                (u'None', u'1', u'id', 1,
                 CI_CHANGE_REGISTRATION_TYPES.WAITING.id),
            ]))
Пример #2
0
    def test_create_puppet_change(self):
        hostci = CI(name='s11401.dc2', uid='mm-1')
        hostci.type_id = CI_TYPES.DEVICE.id
        hostci.save()
        p = PuppetAgentsImporter()
        changed_yaml = open(
            os.path.join(CURRENT_DIR, 'cmdb/tests/samples/canonical.yaml'),
        ).read()
        p.import_contents(changed_yaml)
        unchanged_yaml = open(
            os.path.join(
                CURRENT_DIR, 'cmdb/tests/samples/canonical_unchanged.yaml'),
        ).read()
        p.import_contents(unchanged_yaml)
        chg = CIChange.objects.get(type=CI_CHANGE_TYPES.CONF_AGENT.id)
        logs = PuppetLog.objects.filter(
            cichange__host='s11401.dc2').order_by('id')
        self.assertEqual(chg.content_object.host, u's11401.dc2')
        self.assertEqual(chg.content_object.kind, u'apply')
        self.assertEqual(chg.ci, hostci)
        self.assertEqual(chg.type, 2)
        # check parsed logs
        self.assertEqual(len(logs), 16)
        time_iso = logs[0].time.isoformat().split('.')[0]
        self.assertEqual(time_iso, datetime.datetime(
            2010, 12, 31, 0, 56, 37).isoformat())
        # should not import puppet report which has 'unchanged' status
        self.assertEqual(
            CIChangePuppet.objects.filter(status='unchanged').count(), 0)
        # should drop request, when the same configuration ver. + hostname
        # is already present in the database.

        # Now, feed importer with the same yaml the second time...
        p.import_contents(changed_yaml)
        # No change should be registered at this time.
        self.assertEquals(
            chg, CIChange.objects.get(type=CI_CHANGE_TYPES.CONF_AGENT.id)
        )
        self.assertEquals(
            CIChangePuppet.objects.count(), 1
        )
Пример #3
0
 def test_puppet_parser(self):
     hostci = CI(name='s11401.dc2', uid='mm-1')
     hostci.type_id = CI_TYPES.DEVICE.id
     hostci.save()
     p = PuppetAgentsImporter()
     yaml = open(CURRENT_DIR + 'cmdb/tests/samples/canonical.yaml').read()
     p.import_contents(yaml)
     yaml = open(CURRENT_DIR + 'cmdb/tests/samples/canonical_unchanged.yaml').read()
     p.import_contents(yaml)
     chg = CIChange.objects.all()[0]
     logs = PuppetLog.objects.filter(cichange__host='s11401.dc2').order_by('id')
     self.assertEqual(chg.content_object.host, u's11401.dc2')
     self.assertEqual(chg.content_object.kind, u'apply')
     self.assertEqual(chg.ci,hostci)
     self.assertEqual(chg.type, 2)
     # check parsed logs
     self.assertEqual(len(logs), 16)
     time_iso = logs[0].time.isoformat().split('.')[0]
     self.assertEqual(time_iso, datetime.datetime(2010, 12, 31, 0, 56,
         37).isoformat())
     # should not import puppet report which has 'unchanged' status
     self.assertEqual(CIChangePuppet.objects.filter(status='unchanged').count(), 0)
Пример #4
0
    def test_fisheye(self):
        """
        Create Venture/Role and import as CI/CIRelations.
        Now import fisheye xml from samples/* files and compare
        if changes are properly saved into the database,
        and reconcilated.
        """
        x = Venture(symbol='test_venture')
        x.save()
        y = VentureRole(name='test_role', venture=x)
        y.save()
        allegro_ci = CI(name='Allegro', type_id=CI_TYPES.VENTURE.id)
        allegro_ci.save()

        ct=ContentType.objects.get_for_model(x)
        test_venture, = CIImporter().import_all_ci([ct],asset_id=x.id)

        ct=ContentType.objects.get_for_model(y)
        test_role, = CIImporter().import_all_ci([ct],asset_id=y.id)

        CIImporter().import_relations(ContentType.objects.get_for_model(y),asset_id=y.id)

        with mock.patch('ralph.cmdb.integration.lib.fisheye.Fisheye') as Fisheye:
            Fisheye.side_effect = MockFisheye
            x = pgi(fisheye_class=Fisheye)
            x.import_git()

        self.assertEqual(CIChangeGit.objects.filter(
            author__contains='*****@*****.**',
            #file_paths__contains='/test_venture'
            ).count(), 2)

        self.assertEqual(CIChange.objects.filter(
            ci=test_role,
            type=CI_CHANGE_TYPES.CONF_GIT.id,
        ).count(), 2)