def testNormalizeServiceLogConfigs(self): sampleLogConfig = { 'filters': ['supervisord'], 'path': '/opt/zenoss/log/Z2.log', 'type': 'pythondaemon' } auditLogConfig = { 'filters': ['supervisord'], 'path': '/opt/zenoss/log/audit.log', 'type': 'zenossaudit' } tests = ({}, { 'LogConfigs': [] }, { 'LogConfigs': [auditLogConfig] }, { 'LogConfigs': [sampleLogConfig] }, { 'LogConfigs': [sampleLogConfig, auditLogConfig] }, { 'LogConfigs': [auditLogConfig, sampleLogConfig] }) for service in tests: inputLength = len(service.get('LogConfigs', [])) if auditLogConfig in service.get('LogConfigs', []): LogConfigs = ZenPack.normalizeService(service, {}, '')['LogConfigs'] self.assertEquals(len(LogConfigs), inputLength) else: LogConfigs = ZenPack.normalizeService(service, {}, '')['LogConfigs'] self.assertEquals(len(LogConfigs), inputLength + 1) self.assertIn(auditLogConfig, LogConfigs)
def testNormalizeServiceImage(self): try: image = 'foobar' os.environ['SERVICED_SERVICE_IMAGE'] = image tests = (({'ImageID': ''}, image), ({'ImageID': 'xxx'}, 'xxx')) for service, expected in tests: actual = ZenPack.normalizeService(service, {}, '')['ImageID'] self.assertEquals(actual, expected) finally: del os.environ['SERVICED_SERVICE_IMAGE']
def testNormalizeServiceConfig(self): service = { 'ConfigFiles': { 'missing': {}, 'empty': { 'Content': '' }, 'present': { 'Content': 'present Content' } } } configMap = {'missing': 'missing Content', 'empty': 'empty Content'} expected = dict(present=service['ConfigFiles']['present']['Content'], **configMap) configFiles = ZenPack.normalizeService(service, configMap, '')['ConfigFiles'] for key, value in configFiles.iteritems(): self.assertEquals(expected[key], value['Content'])
def testNormalizeServiceTags(self): tag = 'foobar' tests = ({}, {"Tags": ['some', 'tags']}) for service in tests: tags = ZenPack.normalizeService(service, {}, tag)['Tags'] self.assertIn(tag, tags)