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), ]))
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)
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), ]) )
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)
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 )
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)
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)