def setUp(self):
     self.cache_clear = MagicMock()
     self.cache_true = MagicMock(return_value=True)
     self.cache_false = MagicMock(return_value=False)
     self.cache_update = MagicMock()
     self.cache_set = MagicMock()
     self.cache_del = MagicMock()
     self.config = WorkerConfiguration(
         personality='worker',
         hostname='worker01',
         coordinator_uri='http://192.168.1.2/v1')
     self.config_json = jsonutils.dumps(self.config.format())
     self.cache_get_config = MagicMock(return_value=self.config_json)
Beispiel #2
0
class WhenTestingWorkerConfigurationObject(unittest.TestCase):
    def setUp(self):
        self.worker_config = WorkerConfiguration(
            "correlation", "meniscus.personas.worker.correlation",
            "94d6176b-9188-4409-8648-7374d0326e6b",
            "8cc3b103-9b23-4e1c-afb1-8c5973621b55",
            "http://172.22.15.25:8080/v1")

    def test_worker_configuration(self):
        self.assertEqual(self.worker_config.personality, 'correlation')
        self.assertEqual(self.worker_config.personality_module,
                         'meniscus.personas.worker.correlation')
        self.assertEqual(self.worker_config.worker_token,
                         '94d6176b-9188-4409-8648-7374d0326e6b')
        self.assertEqual(self.worker_config.worker_id,
                         '8cc3b103-9b23-4e1c-afb1-8c5973621b55')
        self.assertEqual(self.worker_config.coordinator_uri,
                         'http://172.22.15.25:8080/v1')

    def test_worker_configuration_format(self):
        worker_dict = self.worker_config.format()
        self.assertEqual(worker_dict['personality'], 'correlation')
        self.assertEqual(worker_dict['personality_module'],
                         'meniscus.personas.worker.correlation')
        self.assertEqual(worker_dict['worker_token'],
                         '94d6176b-9188-4409-8648-7374d0326e6b')
        self.assertEqual(worker_dict['worker_id'],
                         '8cc3b103-9b23-4e1c-afb1-8c5973621b55')
        self.assertEqual(worker_dict['coordinator_uri'],
                         'http://172.22.15.25:8080/v1')
Beispiel #3
0
    def _register_with_coordinator(self, coordinator_uri, personality,
                                   registration, auth_header):
        """
        register with the coordinator and persist the configuration to cache
        """
        try:
            resp = http_request(coordinator_uri + '/pairing',
                                auth_header,
                                jsonutils.dumps(registration),
                                http_verb='POST')

        except requests.RequestException:
            _LOG.exception(
                'Pairing Process: error posting worker registration')
            return False

        _LOG.debug('resp.status_code: {0}'.format(resp.status_code))

        if resp.status_code == httplib.ACCEPTED:
            body = resp.json()['worker_identity']
            config = WorkerConfiguration(personality,
                                         body['personality_module'],
                                         body['worker_token'],
                                         body['worker_id'], coordinator_uri)

            config_cache = ConfigCache()
            config_cache.set_config(config)

            return True
Beispiel #4
0
 def get_config(self):
     if self.cache.cache_exists('worker_configuration', CACHE_CONFIG):
         config = jsonutils.loads(
             self.cache.cache_get('worker_configuration', CACHE_CONFIG))
         worker_config = WorkerConfiguration(**config)
         return worker_config
     return None
Beispiel #5
0
    def setUp(self):

        self.timestamp = "2013-03-19T18:16:48.411029Z"
        self.producers = [
            EventProducer(432, 'producer1', 'syslog', durable=True),
            EventProducer(433, 'producer2', 'syslog', durable=False)
        ]
        self.token = Token('ffe7104e-8d93-47dc-a49a-8fb0d39e5192',
                           'bbd6302e-8d93-47dc-a49a-8fb0d39e5192',
                           "2013-03-19T18:16:48.411029Z")
        self.tenant_id = '1234'
        self.tenant = Tenant(self.tenant_id,
                             self.token,
                             event_producers=self.producers)
        self.tenant_found = MagicMock(return_value=self.tenant)

        self.cache = MagicMock()
        self.valid_message_token = 'ffe7104e-8d93-47dc-a49a-8fb0d39e5192'
        self.invalid_message_token = 'yyy7104e-8d93-47dc-a49a-8fb0d39e5192'
        self.get_token = MagicMock(return_value=self.token)
        self.get_tenant = MagicMock(return_value=self.tenant)
        self.get_none = MagicMock(return_value=None)
        self.config = WorkerConfiguration(
            personality='correlation',
            personality_module='meniscus.personas.worker.correlation.app',
            worker_id='fgc7104e-8d93-47dc-a49a-8fb0d39e5192',
            worker_token='bbd6307f-8d93-47dc-a49a-8fb0d39e5192',
            coordinator_uri='http://192.168.1.2/v1')
        self.get_config = MagicMock(return_value=self.config)
Beispiel #6
0
class WhenTestingWorkerConfigurationObject(unittest.TestCase):

    def setUp(self):
        self.worker_config = WorkerConfiguration(
            "correlation",
            "meniscus.personas.worker.correlation",
            "94d6176b-9188-4409-8648-7374d0326e6b",
            "8cc3b103-9b23-4e1c-afb1-8c5973621b55",
            "http://172.22.15.25:8080/v1")

    def test_worker_configuration(self):
        self.assertEqual(self.worker_config.personality, 'correlation')
        self.assertEqual(self.worker_config.personality_module,
                         'meniscus.personas.worker.correlation')
        self.assertEqual(self.worker_config.worker_token,
                         '94d6176b-9188-4409-8648-7374d0326e6b')
        self.assertEqual(self.worker_config.worker_id,
                         '8cc3b103-9b23-4e1c-afb1-8c5973621b55')
        self.assertEqual(self.worker_config.coordinator_uri,
                         'http://172.22.15.25:8080/v1')

    def test_worker_configuration_format(self):
        worker_dict = self.worker_config.format()
        self.assertEqual(worker_dict['personality'], 'correlation')
        self.assertEqual(worker_dict['personality_module'],
                         'meniscus.personas.worker.correlation')
        self.assertEqual(worker_dict['worker_token'],
                         '94d6176b-9188-4409-8648-7374d0326e6b')
        self.assertEqual(worker_dict['worker_id'],
                         '8cc3b103-9b23-4e1c-afb1-8c5973621b55')
        self.assertEqual(worker_dict['coordinator_uri'],
                         'http://172.22.15.25:8080/v1')
Beispiel #7
0
 def setUp(self):
     self.worker_config = WorkerConfiguration(
         "correlation",
         "meniscus.personas.worker.correlation",
         "94d6176b-9188-4409-8648-7374d0326e6b",
         "8cc3b103-9b23-4e1c-afb1-8c5973621b55",
         "http://172.22.15.25:8080/v1")
 def setUp(self):
     self.cache_clear = MagicMock()
     self.cache_true = MagicMock(return_value=True)
     self.cache_false = MagicMock(return_value=False)
     self.cache_update = MagicMock()
     self.cache_set = MagicMock()
     self.cache_del = MagicMock()
     self.config = WorkerConfiguration(
         personality='worker',
         hostname='worker01',
         coordinator_uri='http://192.168.1.2/v1')
     self.config_json = jsonutils.dumps(self.config.format())
     self.cache_get_config = MagicMock(return_value=self.config_json)
Beispiel #9
0
def bootstrap_api():
    # Persist the coordinator_uri and personality to ConfigCache
    config = WorkerConfiguration(PERSONALITY, platform.node(), COORDINATOR_URI)
    config_cache.set_config(config)

    personality_module = 'meniscus.personas.{0}.app'.format(PERSONALITY)
    _LOG.info(
        'loading default personality module: {0}'.format(personality_module))

    #load the personality module as a plug in
    plugin_mod = import_module(personality_module)

    #start up the api from the specified personality_module
    return plugin_mod.start_up()
 def setUp(self):
     self.cache_clear = MagicMock()
     self.cache_true = MagicMock(return_value=True)
     self.cache_false = MagicMock(return_value=False)
     self.cache_update = MagicMock()
     self.cache_set = MagicMock()
     self.cache_del = MagicMock()
     self.config = WorkerConfiguration(
         personality='correlation',
         personality_module='meniscus.personas.worker.correlation.app',
         worker_id='fgc7104e-8d93-47dc-a49a-8fb0d39e5192',
         worker_token='bbd6307f-8d93-47dc-a49a-8fb0d39e5192',
         coordinator_uri='http://192.168.1.2/v1')
     self.config_json = jsonutils.dumps(self.config.format())
     self.cache_get_config = MagicMock(return_value=self.config_json)
     self.routes = [{
         "service_domain":
         "correlation|normalization|storage",
         "targets": [{
             "worker_id": "488eb3fc-34dd-48ad-a1bb-99ee2a43bf1d",
             "ip_address_v4": "192.168.100.101",
             "ip_address_v6": "::1",
             "status": "online|draining"
         }, {
             "worker_id": "e0ac0dc3-694e-4522-94f0-fb25a4dbb8a1",
             "ip_address_v4": "192.168.100.102",
             "ip_address_v6": "::1",
             "status": "online|draining"
         }, {
             "worker_id": "64d7a5ab-55b6-4ff7-b362-0d67544bb6f8",
             "ip_address_v4": "192.168.100.103",
             "ip_address_v6": "::1",
             "status": "online|draining"
         }]
     }]
     self.routes_json = jsonutils.dumps(self.routes)
     self.cache_get_routes = MagicMock(return_value=self.routes_json)
Beispiel #11
0
class WhenTestingWorkerConfigurationObject(unittest.TestCase):
    def setUp(self):
        self.worker_config = WorkerConfiguration(
            "worker", "worker01", "http://172.22.15.25:8080/v1")

    def test_worker_configuration(self):
        self.assertEqual(self.worker_config.personality, 'worker')
        self.assertEqual(self.worker_config.hostname, 'worker01')
        self.assertEqual(self.worker_config.coordinator_uri,
                         'http://172.22.15.25:8080/v1')

    def test_worker_configuration_format(self):
        worker_dict = self.worker_config.format()
        self.assertEqual(worker_dict['personality'], 'worker')
        self.assertEqual(worker_dict['hostname'], 'worker01')
        self.assertEqual(worker_dict['coordinator_uri'],
                         'http://172.22.15.25:8080/v1')
    def setUp(self):
        self.api_secret = "3F2504E0-4F89-11D3-9A0C-0305E82C3301"
        self.coordinator_uri = "http://localhost:8080/v1"
        self.personality = 'normalization'
        self.pairing_process = PairingProcess(self.api_secret,
                                              self.coordinator_uri,
                                              self.personality)
        self.native_proxy = MagicMock()
        self.get_config = WorkerConfiguration(
            personality='pairing',
            personality_module='meniscus.personas.pairing.app',
            worker_token='token_id',
            worker_id='worker_id',
            coordinator_uri="192.168.1.1:8080/v1")

        self.resp = requests.Response()
        self.http_request = MagicMock(return_value=self.resp)
        self.registration = WorkerRegistration(personality='correlation')\
            .format()
Beispiel #13
0
 def setUp(self):
     self.cache_clear = MagicMock()
     self.cache_true = MagicMock(return_value=True)
     self.cache_false = MagicMock(return_value=False)
     self.cache_update = MagicMock()
     self.cache_set = MagicMock()
     self.cache_del = MagicMock()
     self.config = WorkerConfiguration(
         personality='correlation',
         personality_module='meniscus.personas.worker.correlation.app',
         worker_id='fgc7104e-8d93-47dc-a49a-8fb0d39e5192',
         worker_token='bbd6307f-8d93-47dc-a49a-8fb0d39e5192',
         coordinator_uri='http://192.168.1.2/v1')
     self.config_json = jsonutils.dumps(self.config.format())
     self.cache_get_config = MagicMock(return_value=self.config_json)
     self.routes = [
         {
             "service_domain": "correlation|normalization|storage",
             "targets": [
                 {
                     "worker_id": "488eb3fc-34dd-48ad-a1bb-99ee2a43bf1d",
                     "ip_address_v4": "192.168.100.101",
                     "ip_address_v6": "::1",
                     "status": "online|draining"
                 },
                 {
                     "worker_id": "e0ac0dc3-694e-4522-94f0-fb25a4dbb8a1",
                     "ip_address_v4": "192.168.100.102",
                     "ip_address_v6": "::1",
                     "status": "online|draining"
                 },
                 {
                     "worker_id": "64d7a5ab-55b6-4ff7-b362-0d67544bb6f8",
                     "ip_address_v4": "192.168.100.103",
                     "ip_address_v6": "::1",
                     "status": "online|draining"
                 }
             ]
         }
     ]
     self.routes_json = jsonutils.dumps(self.routes)
     self.cache_get_routes = MagicMock(return_value=self.routes_json)
Beispiel #14
0
class WhenTestingWorkerConfigurationObject(unittest.TestCase):

    def setUp(self):
        self.worker_config = WorkerConfiguration(
            "worker",
            "worker01",
            "http://172.22.15.25:8080/v1")

    def test_worker_configuration(self):
        self.assertEqual(self.worker_config.personality, 'worker')
        self.assertEqual(self.worker_config.hostname, 'worker01')
        self.assertEqual(self.worker_config.coordinator_uri,
                         'http://172.22.15.25:8080/v1')

    def test_worker_configuration_format(self):
        worker_dict = self.worker_config.format()
        self.assertEqual(worker_dict['personality'], 'worker')
        self.assertEqual(worker_dict['hostname'], 'worker01')
        self.assertEqual(worker_dict['coordinator_uri'],
                         'http://172.22.15.25:8080/v1')
Beispiel #15
0
    def setUp(self):
        self.conf = MagicMock()
        self.conf.status_update.worker_status_interval = 60
        self.get_config = MagicMock(return_value=self.conf)
        self.config = WorkerConfiguration(
            personality='worker',
            hostname='worker01',
            coordinator_uri='http://192.168.1.2/v1')
        self.system_info = SystemInfo().format()
        self.request_uri = "{0}/worker/{1}/status".format(
            self.config.coordinator_uri, self.config.hostname)

        self.worker_status = {
            'worker_status': Worker(personality='worker').format()
        }
        self.worker_status['worker_status']['system_info'] = self.system_info
        self.req_body = jsonutils.dumps(self.worker_status)

        self.get_config = MagicMock(return_value=self.config)
        self.resp = requests.Response()
        self.http_request = MagicMock(return_value=self.resp)
Beispiel #16
0
 def setUp(self):
     self.conf = MagicMock()
     self.conf.status_update.worker_status_interval = 60
     self.get_config = MagicMock(return_value=self.conf)
     self.config = WorkerConfiguration(
         personality='worker.correlation',
         personality_module='meniscus.personas.worker.correlation.app',
         worker_id='fgc7104e-8d93-47dc-a49a-8fb0d39e5192',
         worker_token='bbd6307f-8d93-47dc-a49a-8fb0d39e5192',
         coordinator_uri='http://192.168.1.2/v1')
     self.system_info = SystemInfo()
     self.info_format = MagicMock(return_value=self.system_info.format())
     self.request_uri = "{0}/worker/{1}/status".format(
         self.config.coordinator_uri, self.config.worker_id)
     self.req_body = jsonutils.dumps({
         'worker_status': {
             'status': 'online',
             'system_info': self.system_info.format()
         }
     })
     self.get_config = MagicMock(return_value=self.config)
     self.resp = requests.Response()
     self.http_request = MagicMock(return_value=self.resp)
Beispiel #17
0
 def setUp(self):
     self.tenant_id = '5164b8f4-16fb-4376-9d29-8a6cbaa02fa9'
     self.message_token = 'ffe7104e-8d93-47dc-a49a-8fb0d39e5192'
     self.producers = [
         EventProducer(432, 'producer1', 'syslog', durable=True),
         EventProducer(433, 'producer2', 'syslog', durable=False)
     ]
     self.invalid_message_token = 'yyy7104e-8d93-47dc-a49a-8fb0d39e5192'
     self.token = Token('ffe7104e-8d93-47dc-a49a-8fb0d39e5192',
                        'bbd6302e-8d93-47dc-a49a-8fb0d39e5192',
                        '2013-03-19T18:16:48.411029Z')
     self.tenant = Tenant(self.tenant_id,
                          self.token,
                          event_producers=self.producers)
     self.get_token = MagicMock(return_value=self.token)
     self.get_tenant = MagicMock(return_value=self.tenant)
     self.get_none = MagicMock(return_value=None)
     self.src_msg = {
         'HOST':
         'tohru',
         '_SDATA': {
             'meniscus': {
                 'token': self.message_token,
                 'tenant': self.tenant_id
             }
         },
         'PRIORITY':
         'info',
         'MESSAGE':
         '127.0.0.1 - - [12/Jul/2013:19:40:58 +0000] '
         '\'GET /test.html HTTP/1.1\' 404 466 \'-\' '
         '\'curl/7.29.0\'',
         'FACILITY':
         'local1',
         'MSGID':
         '345',
         'ISODATE':
         '2013-07-12T14:17:00+00:00',
         'PROGRAM':
         'apache',
         'DATE':
         '2013-07-12T14:17:00.134+00:00',
         'PID':
         '234'
     }
     self.malformed_sys_msg = {
         'HOST':
         'tohru',
         '_SDATA': {
             'meniscus': {
                 'token': '',
                 'tenant': ''
             }
         },
         'PRIORITY':
         'info',
         'MESSAGE':
         '127.0.0.1 - - [12/Jul/2013:19:40:58 +0000] '
         '\'GET /test.html HTTP/1.1\' 404 466 \'-\' '
         '\'curl/7.29.0\'',
         'FACILITY':
         'local1',
         'MSGID':
         '345',
         'ISODATE':
         '2013-07-12T14:17:00+00:00',
         'PROGRAM':
         'apache',
         'DATE':
         '2013-07-12T14:17:00.134+00:00',
         'PID':
         '234'
     }
     self.cee_msg = {
         'host':
         'tohru',
         'pri':
         'info',
         'msg':
         '127.0.0.1 - - [12/Jul/2013:19:40:58 +0000] '
         '\'GET /test.html HTTP/1.1\' 404 466 \'-\' '
         '\'curl/7.29.0\'',
         'msgid':
         '345',
         'time':
         '2013-07-12T14:17:00+00:00',
         'pname':
         'apache',
         'pid':
         '234',
         'ver':
         '1',
         'native': {
             'meniscus': {
                 'token': 'ffe7104e-8d93-47dc-a49a-8fb0d39e5192',
                 'tenant': '5164b8f4-16fb-4376-9d29-8a6cbaa02fa9'
             }
         }
     }
     self.config = WorkerConfiguration(
         personality='worker',
         hostname='worker01',
         coordinator_uri='http://192.168.1.2/v1')
     self.get_config = MagicMock(return_value=self.config)
     self.tenant_found = MagicMock(return_value=self.tenant)
Beispiel #18
0
 def setUp(self):
     self.worker_config = WorkerConfiguration(
         "worker",
         "worker01",
         "http://172.22.15.25:8080/v1")
class WhenTestingConfigCache(unittest.TestCase):
    def setUp(self):
        self.cache_clear = MagicMock()
        self.cache_true = MagicMock(return_value=True)
        self.cache_false = MagicMock(return_value=False)
        self.cache_update = MagicMock()
        self.cache_set = MagicMock()
        self.cache_del = MagicMock()
        self.config = WorkerConfiguration(
            personality='correlation',
            personality_module='meniscus.personas.worker.correlation.app',
            worker_id='fgc7104e-8d93-47dc-a49a-8fb0d39e5192',
            worker_token='bbd6307f-8d93-47dc-a49a-8fb0d39e5192',
            coordinator_uri='http://192.168.1.2/v1')
        self.config_json = jsonutils.dumps(self.config.format())
        self.cache_get_config = MagicMock(return_value=self.config_json)
        self.routes = [{
            "service_domain":
            "correlation|normalization|storage",
            "targets": [{
                "worker_id": "488eb3fc-34dd-48ad-a1bb-99ee2a43bf1d",
                "ip_address_v4": "192.168.100.101",
                "ip_address_v6": "::1",
                "status": "online|draining"
            }, {
                "worker_id": "e0ac0dc3-694e-4522-94f0-fb25a4dbb8a1",
                "ip_address_v4": "192.168.100.102",
                "ip_address_v6": "::1",
                "status": "online|draining"
            }, {
                "worker_id": "64d7a5ab-55b6-4ff7-b362-0d67544bb6f8",
                "ip_address_v4": "192.168.100.103",
                "ip_address_v6": "::1",
                "status": "online|draining"
            }]
        }]
        self.routes_json = jsonutils.dumps(self.routes)
        self.cache_get_routes = MagicMock(return_value=self.routes_json)

    def test_clear_calls_cache_clear(self):
        with patch.object(NativeProxy, 'cache_clear', self.cache_clear):
            config_cache = ConfigCache()
            config_cache.clear()
        self.cache_clear.assert_called_once_with(CACHE_CONFIG)

    def test_set_config_calls_cache_update(self):
        with patch.object(NativeProxy, 'cache_exists',
                          self.cache_true), patch.object(
                              NativeProxy, 'cache_update', self.cache_update):
            config_cache = ConfigCache()
            config_cache.set_config(self.config)

        self.cache_update.assert_called_once_with(
            'worker_configuration', jsonutils.dumps(self.config.format()),
            CONFIG_EXPIRES, CACHE_CONFIG)

    def test_set_config_calls_cache_set(self):
        with patch.object(NativeProxy, 'cache_exists',
                          self.cache_false), patch.object(
                              NativeProxy, 'cache_set', self.cache_set):
            config_cache = ConfigCache()
            config_cache.set_config(self.config)

        self.cache_set.assert_called_once_with(
            'worker_configuration', jsonutils.dumps(self.config.format()),
            CONFIG_EXPIRES, CACHE_CONFIG)

    def test_get_config_calls_returns_config(self):
        with patch.object(NativeProxy, 'cache_exists',
                          self.cache_true), patch.object(
                              NativeProxy, 'cache_get', self.cache_get_config):
            config_cache = ConfigCache()
            config = config_cache.get_config()

        self.cache_get_config.assert_called_once_with('worker_configuration',
                                                      CACHE_CONFIG)
        self.assertIsInstance(config, WorkerConfiguration)

    def test_get_config_calls_returns_none(self):
        with patch.object(NativeProxy, 'cache_exists', self.cache_false):
            config_cache = ConfigCache()
            config = config_cache.get_config()

        self.assertIs(config, None)

    def test_delete_config_calls_cache_del(self):
        with patch.object(NativeProxy, 'cache_exists',
                          self.cache_true), patch.object(
                              NativeProxy, 'cache_del', self.cache_del):
            config_cache = ConfigCache()
            config_cache.delete_config()

        self.cache_del.assert_called_once_with('worker_configuration',
                                               CACHE_CONFIG)

    def test_delete_config_does_not_call_cache_del(self):
        with patch.object(NativeProxy, 'cache_exists',
                          self.cache_false), patch.object(
                              NativeProxy, 'cache_del', self.cache_del):
            config_cache = ConfigCache()
            config_cache.delete_config()

        with self.assertRaises(AssertionError):
            self.cache_del.assert_called_once_with('worker_configuration',
                                                   CACHE_CONFIG)
class WhenTestingConfigCache(unittest.TestCase):
    def setUp(self):
        self.cache_clear = MagicMock()
        self.cache_true = MagicMock(return_value=True)
        self.cache_false = MagicMock(return_value=False)
        self.cache_update = MagicMock()
        self.cache_set = MagicMock()
        self.cache_del = MagicMock()
        self.config = WorkerConfiguration(
            personality='worker',
            hostname='worker01',
            coordinator_uri='http://192.168.1.2/v1')
        self.config_json = jsonutils.dumps(self.config.format())
        self.cache_get_config = MagicMock(return_value=self.config_json)

    def test_clear_calls_cache_clear(self):
        with patch.object(NativeProxy, 'cache_clear', self.cache_clear):
            config_cache = ConfigCache()
            config_cache.clear()
        self.cache_clear.assert_called_once_with(CACHE_CONFIG)

    def test_set_config_calls_cache_update(self):
        with patch.object(
                NativeProxy, 'cache_exists', self.cache_true
        ), patch.object(NativeProxy, 'cache_update', self.cache_update):
            config_cache = ConfigCache()
            config_cache.set_config(self.config)

        self.cache_update.assert_called_once_with(
            'worker_configuration', jsonutils.dumps(self.config.format()),
            CONFIG_EXPIRES, CACHE_CONFIG)

    def test_set_config_calls_cache_set(self):
        with patch.object(
                NativeProxy, 'cache_exists', self.cache_false
        ), patch.object(NativeProxy, 'cache_set', self.cache_set):
            config_cache = ConfigCache()
            config_cache.set_config(self.config)

        self.cache_set.assert_called_once_with(
            'worker_configuration', jsonutils.dumps(self.config.format()),
            CONFIG_EXPIRES, CACHE_CONFIG)

    def test_get_config_calls_returns_config(self):
        with patch.object(
                NativeProxy, 'cache_exists', self.cache_true
        ), patch.object(NativeProxy, 'cache_get',  self.cache_get_config):
            config_cache = ConfigCache()
            config = config_cache.get_config()

        self.cache_get_config.assert_called_once_with(
            'worker_configuration', CACHE_CONFIG)
        self.assertIsInstance(config, WorkerConfiguration)

    def test_get_config_calls_returns_none(self):
        with patch.object(
                NativeProxy, 'cache_exists', self.cache_false):
            config_cache = ConfigCache()
            config = config_cache.get_config()

        self.assertIs(config, None)

    def test_delete_config_calls_cache_del(self):
        with patch.object(
                NativeProxy, 'cache_exists', self.cache_true
        ), patch.object(NativeProxy, 'cache_del', self.cache_del):
            config_cache = ConfigCache()
            config_cache.delete_config()

        self.cache_del.assert_called_once_with(
            'worker_configuration', CACHE_CONFIG)

    def test_delete_config_does_not_call_cache_del(self):
        with patch.object(
                NativeProxy, 'cache_exists', self.cache_false
        ), patch.object(NativeProxy, 'cache_del', self.cache_del):
            config_cache = ConfigCache()
            config_cache.delete_config()

        with self.assertRaises(AssertionError):
            self.cache_del.assert_called_once_with(
                'worker_configuration', CACHE_CONFIG)
Beispiel #21
0
class WhenTestingConfigCache(unittest.TestCase):
    def setUp(self):
        self.cache_clear = MagicMock()
        self.cache_true = MagicMock(return_value=True)
        self.cache_false = MagicMock(return_value=False)
        self.cache_update = MagicMock()
        self.cache_set = MagicMock()
        self.cache_del = MagicMock()
        self.config = WorkerConfiguration(
            personality='correlation',
            personality_module='meniscus.personas.worker.correlation.app',
            worker_id='fgc7104e-8d93-47dc-a49a-8fb0d39e5192',
            worker_token='bbd6307f-8d93-47dc-a49a-8fb0d39e5192',
            coordinator_uri='http://192.168.1.2/v1')
        self.config_json = jsonutils.dumps(self.config.format())
        self.cache_get_config = MagicMock(return_value=self.config_json)
        self.routes = [
            {
                "service_domain": "correlation|normalization|storage",
                "targets": [
                    {
                        "worker_id": "488eb3fc-34dd-48ad-a1bb-99ee2a43bf1d",
                        "ip_address_v4": "192.168.100.101",
                        "ip_address_v6": "::1",
                        "status": "online|draining"
                    },
                    {
                        "worker_id": "e0ac0dc3-694e-4522-94f0-fb25a4dbb8a1",
                        "ip_address_v4": "192.168.100.102",
                        "ip_address_v6": "::1",
                        "status": "online|draining"
                    },
                    {
                        "worker_id": "64d7a5ab-55b6-4ff7-b362-0d67544bb6f8",
                        "ip_address_v4": "192.168.100.103",
                        "ip_address_v6": "::1",
                        "status": "online|draining"
                    }
                ]
            }
        ]
        self.routes_json = jsonutils.dumps(self.routes)
        self.cache_get_routes = MagicMock(return_value=self.routes_json)

    def test_clear_calls_cache_clear(self):
        with patch.object(NativeProxy, 'cache_clear', self.cache_clear):
            config_cache = ConfigCache()
            config_cache.clear()
        self.cache_clear.assert_called_once_with(CACHE_CONFIG)

    def test_set_config_calls_cache_update(self):
        with patch.object(
                NativeProxy, 'cache_exists', self.cache_true
        ), patch.object(NativeProxy, 'cache_update', self.cache_update):
            config_cache = ConfigCache()
            config_cache.set_config(self.config)

        self.cache_update.assert_called_once_with(
            'worker_configuration', jsonutils.dumps(self.config.format()),
            CONFIG_EXPIRES, CACHE_CONFIG)

    def test_set_config_calls_cache_set(self):
        with patch.object(
                NativeProxy, 'cache_exists', self.cache_false
        ), patch.object(NativeProxy, 'cache_set', self.cache_set):
            config_cache = ConfigCache()
            config_cache.set_config(self.config)

        self.cache_set.assert_called_once_with(
            'worker_configuration', jsonutils.dumps(self.config.format()),
            CONFIG_EXPIRES, CACHE_CONFIG)

    def test_get_config_calls_returns_config(self):
        with patch.object(
                NativeProxy, 'cache_exists', self.cache_true
        ), patch.object(NativeProxy, 'cache_get',  self.cache_get_config):
            config_cache = ConfigCache()
            config = config_cache.get_config()

        self.cache_get_config.assert_called_once_with(
            'worker_configuration', CACHE_CONFIG)
        self.assertIsInstance(config, WorkerConfiguration)

    def test_get_config_calls_returns_none(self):
        with patch.object(
                NativeProxy, 'cache_exists', self.cache_false):
            config_cache = ConfigCache()
            config = config_cache.get_config()

        self.assertIs(config, None)

    def test_delete_config_calls_cache_del(self):
        with patch.object(
                NativeProxy, 'cache_exists', self.cache_true
        ), patch.object(NativeProxy, 'cache_del', self.cache_del):
            config_cache = ConfigCache()
            config_cache.delete_config()

        self.cache_del.assert_called_once_with(
            'worker_configuration', CACHE_CONFIG)

    def test_delete_config_does_not_call_cache_del(self):
        with patch.object(
                NativeProxy, 'cache_exists', self.cache_false
        ), patch.object(NativeProxy, 'cache_del', self.cache_del):
            config_cache = ConfigCache()
            config_cache.delete_config()

        with self.assertRaises(AssertionError):
            self.cache_del.assert_called_once_with(
                'worker_configuration', CACHE_CONFIG)
Beispiel #22
0
 def setUp(self):
     self.worker_config = WorkerConfiguration(
         "worker", "worker01", "http://172.22.15.25:8080/v1")
Beispiel #23
0
 def setUp(self):
     self.worker_config = WorkerConfiguration(
         "correlation", "meniscus.personas.worker.correlation",
         "94d6176b-9188-4409-8648-7374d0326e6b",
         "8cc3b103-9b23-4e1c-afb1-8c5973621b55",
         "http://172.22.15.25:8080/v1")
class WhenTestingConfigCache(unittest.TestCase):
    def setUp(self):
        self.cache_clear = MagicMock()
        self.cache_true = MagicMock(return_value=True)
        self.cache_false = MagicMock(return_value=False)
        self.cache_update = MagicMock()
        self.cache_set = MagicMock()
        self.cache_del = MagicMock()
        self.config = WorkerConfiguration(
            personality='worker',
            hostname='worker01',
            coordinator_uri='http://192.168.1.2/v1')
        self.config_json = jsonutils.dumps(self.config.format())
        self.cache_get_config = MagicMock(return_value=self.config_json)

    def test_clear_calls_cache_clear(self):
        with patch.object(NativeProxy, 'cache_clear', self.cache_clear):
            config_cache = ConfigCache()
            config_cache.clear()
        self.cache_clear.assert_called_once_with(CACHE_CONFIG)

    def test_set_config_calls_cache_update(self):
        with patch.object(NativeProxy, 'cache_exists',
                          self.cache_true), patch.object(
                              NativeProxy, 'cache_update', self.cache_update):
            config_cache = ConfigCache()
            config_cache.set_config(self.config)

        self.cache_update.assert_called_once_with(
            'worker_configuration', jsonutils.dumps(self.config.format()),
            CONFIG_EXPIRES, CACHE_CONFIG)

    def test_set_config_calls_cache_set(self):
        with patch.object(NativeProxy, 'cache_exists',
                          self.cache_false), patch.object(
                              NativeProxy, 'cache_set', self.cache_set):
            config_cache = ConfigCache()
            config_cache.set_config(self.config)

        self.cache_set.assert_called_once_with(
            'worker_configuration', jsonutils.dumps(self.config.format()),
            CONFIG_EXPIRES, CACHE_CONFIG)

    def test_get_config_calls_returns_config(self):
        with patch.object(NativeProxy, 'cache_exists',
                          self.cache_true), patch.object(
                              NativeProxy, 'cache_get', self.cache_get_config):
            config_cache = ConfigCache()
            config = config_cache.get_config()

        self.cache_get_config.assert_called_once_with('worker_configuration',
                                                      CACHE_CONFIG)
        self.assertIsInstance(config, WorkerConfiguration)

    def test_get_config_calls_returns_none(self):
        with patch.object(NativeProxy, 'cache_exists', self.cache_false):
            config_cache = ConfigCache()
            config = config_cache.get_config()

        self.assertIs(config, None)

    def test_delete_config_calls_cache_del(self):
        with patch.object(NativeProxy, 'cache_exists',
                          self.cache_true), patch.object(
                              NativeProxy, 'cache_del', self.cache_del):
            config_cache = ConfigCache()
            config_cache.delete_config()

        self.cache_del.assert_called_once_with('worker_configuration',
                                               CACHE_CONFIG)

    def test_delete_config_does_not_call_cache_del(self):
        with patch.object(NativeProxy, 'cache_exists',
                          self.cache_false), patch.object(
                              NativeProxy, 'cache_del', self.cache_del):
            config_cache = ConfigCache()
            config_cache.delete_config()

        with self.assertRaises(AssertionError):
            self.cache_del.assert_called_once_with('worker_configuration',
                                                   CACHE_CONFIG)