コード例 #1
0
ファイル: test_detection.py プロジェクト: target/grease
 def test_get_schedule_staged(self):
     d = Detect()
     d.ioc.getCollection('SourceData').insert_one({
         'grease_data': {
             'sourcing': {
                 'server': ObjectId(d.ioc.getConfig().NodeIdentity)
             },
             'detection': {
                 'server': ObjectId(d.ioc.getConfig().NodeIdentity),
                 'detectionStart': None,
                 'detectionEnd': None,
                 'detection': {}
             },
             'scheduling': {
                 'schedulingServer': None,
                 'schedulingStart': None,
                 'schedulingEnd': None
             },
             'execution': {
                 'server': None,
                 'assignmentTime': None,
                 'executionStart': None,
                 'executionEnd': None,
                 'context': {},
                 'executionSuccess': False,
                 'commandSuccess': False,
                 'failures': 0,
                 'retryTime': datetime.datetime.utcnow()
             }
         },
         'source':
         str('test').encode('utf-8'),
         'configuration':
         str('testConfig').encode('utf-8'),
         'data': {
             'dev': 'test'
         },
         'createTime':
         datetime.datetime.utcnow(),
         'expiry':
         Deduplication.generate_max_expiry_time(1)
     })
     self.assertTrue(d.getScheduledSource())
     self.assertEqual(
         d.getScheduledSource().get('grease_data').get('detection').get(
             'server'), ObjectId(d.ioc.getConfig().NodeIdentity))
     d.ioc.getCollection('SourceData').drop()
コード例 #2
0
 def test_scheduleScheduling(self):
     d = Detect()
     p = PrototypeConfig(d.ioc)
     source = {
         'key': 'var',
         'ver': 'key',
         'greg': 'old',
         'created': '2017-11-24'
     }
     configuration = {
         'name': 'demoConfig',
         'job': 'otherThing',
         'exe_env': 'general',
         'source': 'Google',
         'logic': {
             'DateRange': [{
                 'field': 'created',
                 'format': '%Y-%m-%d',
                 'min': '2017-11-23',
                 'max': '2017-11-25'
             }],
             'Regex': [{
                 'field': 'key',
                 'pattern': '.*',
                 'variable': True,
                 'variable_name': 'field'
             }, {
                 'field': 'ver',
                 'pattern': '.*'
             }],
             'Exists': [{
                 'field': 'greg',
                 'variable': True,
                 'variable_name': 'greg'
             }]
         }
     }
     p.load(True, [configuration])
     sourceId = d.ioc.getCollection('SourceData').insert_one({
         'grease_data': {
             'sourcing': {
                 'server': ObjectId(d.ioc.getConfig().NodeIdentity)
             },
             'detection': {
                 'server': ObjectId(d.ioc.getConfig().NodeIdentity),
                 'detectionStart': None,
                 'detectionEnd': None,
                 'detection': {}
             },
             'scheduling': {
                 'schedulingServer': None,
                 'schedulingStart': None,
                 'schedulingEnd': None
             },
             'execution': {
                 'server': None,
                 'assignmentTime': None,
                 'executionStart': None,
                 'executionEnd': None,
                 'context': {},
                 'executionSuccess': False,
                 'commandSuccess': False,
                 'failures': 0,
                 'retryTime': datetime.datetime.utcnow()
             }
         },
         'source':
         str('test').encode('utf-8'),
         'configuration':
         configuration.get('name'),
         'data':
         source,
         'createTime':
         datetime.datetime.utcnow(),
         'expiry':
         Deduplication.generate_max_expiry_time(1)
     }).inserted_id
     scheduleServer = d.ioc.getCollection('JobServer').insert_one({
         'jobs':
         0,
         'os':
         platform.system().lower(),
         'roles': ["general"],
         'prototypes': ["schedule"],
         'active':
         True,
         'activationTime':
         datetime.datetime.utcnow()
     }).inserted_id
     self.assertTrue(d.detectSource())
     self.assertFalse(d.getScheduledSource())
     self.assertTrue(
         len(
             d.ioc.getCollection('SourceData').find_one(
                 {
                     'grease_data.scheduling.server':
                     ObjectId(scheduleServer),
                     'grease_data.scheduling.start': None,
                     'grease_data.scheduling.end': None
                 },
                 sort=[('createTime', pymongo.DESCENDING)])))
     d.ioc.getCollection('JobServer').delete_one(
         {'_id': ObjectId(scheduleServer)})
     d.ioc.getCollection('SourceData').delete_one(
         {'_id': ObjectId(sourceId)})
コード例 #3
0
 def test_scheduling_fail(self):
     d = Detect()
     p = PrototypeConfig(d.ioc)
     s = Scheduler(d.ioc)
     source = {
         'key': 'var',
         'ver': 'key',
         'greg': 'old',
         'created': '2017-11-24'
     }
     configuration = {
         'name': 'demoConfig',
         'job': 'otherThing',
         'exe_env': 'minix',
         'source': 'Google',
         'logic': {
             'DateRange': [
                 {
                     'field': 'created',
                     'format': '%Y-%m-%d',
                     'min': '2017-11-23',
                     'max': '2017-11-25'
                 }
             ],
             'Regex': [
                 {
                     'field': 'key',
                     'pattern': '.*',
                     'variable': True,
                     'variable_name': 'field'
                 },
                 {
                     'field': 'ver',
                     'pattern': '.*'
                 }
             ],
             'Exists': [
                 {
                     'field': 'greg',
                     'variable': True,
                     'variable_name': 'greg'
                 }
             ]
         }
     }
     p.load(True, [configuration])
     sourceId = d.ioc.getCollection('SourceData').insert_one({
                 'grease_data': {
                     'sourcing': {
                         'server': ObjectId(d.ioc.getConfig().NodeIdentity)
                     },
                     'detection': {
                         'server': ObjectId(d.ioc.getConfig().NodeIdentity),
                         'detectionStart': None,
                         'detectionEnd': None,
                         'detection': {}
                     },
                     'scheduling': {
                         'schedulingServer': None,
                         'schedulingStart': None,
                         'schedulingEnd': None
                     },
                     'execution': {
                         'server': None,
                         'assignmentTime': None,
                         'executionStart': None,
                         'executionEnd': None,
                         'context': {},
                         'executionSuccess': False,
                         'commandSuccess': False,
                         'failures': 0,
                         'retryTime': datetime.datetime.utcnow()
                     }
                 },
                 'source': str('test').encode('utf-8'),
                 'configuration': configuration.get('name'),
                 'data': source,
                 'createTime': datetime.datetime.utcnow(),
                 'expiry': Deduplication.generate_max_expiry_time(1)
     }).inserted_id
     d.ioc.getCollection('JobServer').update_one(
         {'_id': ObjectId(d.ioc.getConfig().NodeIdentity)},
         {
             '$set': {
                 'prototypes': ["scan", "detect", "schedule"]
             }
         }
     )
     self.assertTrue(d.detectSource())
     self.assertFalse(d.getScheduledSource())
     self.assertTrue(s.getDetectedSource())
     self.assertFalse(s.scheduleExecution())
     self.assertTrue(d.ioc.getCollection('JobServer').update_one(
         {'_id': ObjectId(d.ioc.getConfig().NodeIdentity)},
         {
             '$set': {
                 'prototypes': []
             }
         }
     ))
     d.ioc.getCollection('SourceData').delete_one({'_id': ObjectId(sourceId)})
コード例 #4
0
ファイル: test_detection.py プロジェクト: target/grease
 def test_get_schedule_empty(self):
     d = Detect()
     self.assertFalse(d.getScheduledSource())