Beispiel #1
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()
     yaml = open(
         djoin(CURRENT_DIR, 'cmdb/tests/samples/canonical.yaml')
     ).read()
     p.import_contents(yaml)
     yaml = open(
         djoin(CURRENT_DIR, 'cmdb/tests/samples/canonical_unchanged.yaml')
     ).read()
     p.import_contents(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)
Beispiel #2
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(os.getcwd()+'/cmdb/tests/samples/canonical.yaml').read()
     p.import_contents(yaml)
     yaml = open(os.getcwd()+'/cmdb/tests/samples/canonical_unchanged.yaml').read()
     p.import_contents(yaml)
     chg = CIChange.objects.all()[0]
     logs = PuppetLog.objects.filter(cichange=chg).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)
     self.assertEqual(logs[0].time, datetime.datetime(2010, 12, 31, 0, 56, 37, 290413))
     # should not import puppet report which has 'unchanged' status
     self.assertEqual(CIChangePuppet.objects.filter(status='unchanged').count(), 0)
Beispiel #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, "s11401.dc2")
     self.assertEqual(chg.content_object.kind, "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)
Beispiel #4
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
        )
Beispiel #5
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)
Beispiel #6
0
def notify_puppet_agent(request):
    contents=request.body
    x = PuppetAgentsImporter()
    x.import_contents(contents)
    return {'ok' : True}
Beispiel #7
0
def notify_puppet_agent(request):
    contents = request.body
    x = PuppetAgentsImporter()
    x.import_contents(contents)
    return {'ok': True}