def test_enforce_admin_only_subattribute(self): action = "create_something" target = {'tenant_id': 'fake', 'attr': {'sub_attr_1': 'x', 'sub_attr_2': 'y'}} result = policy.enforce(context.get_admin_context(), action, target, None) self.assertEqual(True, result)
def setUp(self): super(TestCommonServicesPlugin, self).setUp() self.addCleanup(mock.patch.stopall) self.context = context.get_admin_context() self.event_db_plugin =\ common_services_db_plugin.CommonServicesPluginDb() self.coreutil_plugin = common_services_plugin.CommonServicesPlugin()
def test_apmec_context_admin_to_dict(self): self.db_api_session.return_value = 'fakesession' ctx = context.get_admin_context() ctx_dict = ctx.to_dict() self.assertIsNone(ctx_dict['user_id']) self.assertIsNone(ctx_dict['tenant_id']) self.assertIsNotNone(ctx.session) self.assertNotIn('session', ctx_dict)
def update_mea_with_alarm(self, plugin, context, mea, policy_dict): triggers = policy_dict['triggers'] alarm_url = dict() for trigger_name, trigger_dict in triggers.items(): params = dict() params['mea_id'] = mea['id'] params['mon_policy_name'] = trigger_name driver = trigger_dict['event_type']['implementation'] # TODO(Tung Doan) trigger_dict.get('actions') needs to be used policy_action = trigger_dict.get('action') if len(policy_action) == 0: _log_monitor_events(t_context.get_admin_context(), mea, "Alarm not set: policy action missing") return # Other backend policies with the construct (policy, action) # ex: (SP1, in), (SP1, out) def _refactor_backend_policy(bk_policy_name, bk_action_name): policy = '%(policy_name)s-%(action_name)s' % { 'policy_name': bk_policy_name, 'action_name': bk_action_name } return policy for index, policy_action_name in enumerate(policy_action): filters = {'name': policy_action_name} bkend_policies =\ plugin.get_mea_policies(context, mea['id'], filters) if bkend_policies: bkend_policy = bkend_policies[0] if bkend_policy['type'] == constants.POLICY_SCALING: cp = trigger_dict['condition'].\ get('comparison_operator') scaling_type = 'out' if cp == 'gt' else 'in' policy_action[index] = _refactor_backend_policy( policy_action_name, scaling_type) # Support multiple action. Ex: respawn % notify action_name = '%'.join(policy_action) params['mon_policy_action'] = action_name alarm_url[trigger_name] =\ self.call_alarm_url(driver, mea, params) details = "Alarm URL set successfully: %s" % alarm_url _log_monitor_events(t_context.get_admin_context(), mea, details) return alarm_url
def test_apmec_context_get_admin_context_not_update_local_store(self): ctx = context.Context('user_id', 'tenant_id') req_id_before = oslo_context.get_current().request_id self.assertEqual(req_id_before, ctx.request_id) ctx_admin = context.get_admin_context() self.assertEqual(req_id_before, oslo_context.get_current().request_id) self.assertNotEqual(req_id_before, ctx_admin.request_id)
def setUp(self): super(TestMeoPlugin, self).setUp() self.addCleanup(mock.patch.stopall) self.context = context.get_admin_context() self._mock_driver_manager() mock.patch('apmec.meo.meo_plugin.MeoPlugin._get_vim_from_mea', side_effect=dummy_get_vim).start() self.meo_plugin = meo_plugin.MeoPlugin() mock.patch('apmec.db.common_services.common_services_db_plugin.' 'CommonServicesPluginDb.create_event').start() self._cos_db_plugin =\ common_services_db_plugin.CommonServicesPluginDb()
def setUp(self): super(TestDbPurgeDelete, self).setUp() self.addCleanup(mock.patch.stopall) self.context = context.get_admin_context() self._mock_config() mock.patch('sqlalchemy.Table').start() mock.patch('apmec.db.migration.purge_tables._purge_resource_tables' ).start() mock.patch('apmec.db.migration.purge_tables._purge_events_table', ).start() mock.patch('apmec.db.migration.purge_tables.' '_generate_associated_tables_map').start() mock.patch('apmec.db.migration.purge_tables.get_engine').start()
def add_hosting_mea(self, new_mea): LOG.debug('Adding host %(id)s, Mgmt IP %(ips)s', { 'id': new_mea['id'], 'ips': new_mea['management_ip_addresses'] }) new_mea['boot_at'] = timeutils.utcnow() with self._lock: self._hosting_meas[new_mea['id']] = new_mea attrib_dict = new_mea['mea']['attributes'] mon_policy_dict = attrib_dict['monitoring_policy'] evt_details = (("MEA added for monitoring. " "mon_policy_dict = %s,") % (mon_policy_dict)) _log_monitor_events(t_context.get_admin_context(), new_mea['mea'], evt_details)
def setUp(self): super(TestMEMPlugin, self).setUp() self.addCleanup(mock.patch.stopall) self.context = context.get_admin_context() self._mock_vim_client() self._stub_get_vim() self._mock_device_manager() self._mock_mea_monitor() self._mock_mea_alarm_monitor() self._mock_green_pool() self._insert_dummy_vim() self.mem_plugin = plugin.MEMPlugin() mock.patch('apmec.db.common_services.common_services_db_plugin.' 'CommonServicesPluginDb.create_event').start() self._cos_db_plugin =\ common_services_db_plugin.CommonServicesPluginDb()
def _mark_mea_status(self, mea_id, exclude_status, new_status): context = t_context.get_admin_context() with context.session.begin(subtransactions=True): try: mea_db = (self._model_query(context, MEA).filter( MEA.id == mea_id).filter(~MEA.status.in_(exclude_status)). with_lockmode('update').one()) except orm_exc.NoResultFound: LOG.warning('no mea found %s', mea_id) return False mea_db.update({'status': new_status}) self._cos_db_plg.create_event(context, res_id=mea_id, res_type=constants.RES_TYPE_MEA, res_state=new_status, evt_type=constants.RES_EVT_MONITOR, tstamp=timeutils.utcnow()) return True
def update_vim(self, context, vim_id, status): t_admin_context = t_context.get_admin_context() update_time = timeutils.utcnow() with t_admin_context.session.begin(subtransactions=True): try: query = t_admin_context.session.query(meo_db.Vim) query.filter(meo_db.Vim.id == vim_id).update({ 'status': status, 'updated_at': update_time }) except orm_exc.NoResultFound: raise meo.VimNotFoundException(vim_id=vim_id) event_db = common_services_db.Event( resource_id=vim_id, resource_type=constants.RES_TYPE_VIM, resource_state=status, event_details="", event_type=constants.RES_EVT_MONITOR, timestamp=update_time) t_admin_context.session.add(event_db) return status
def setUp(self): super(TestChainSFC, self).setUp() self.context = context.get_admin_context() self.sfc_driver = openstack_driver.OpenStack_Driver() self._mock_neutron_client() self.addCleanup(mock.patch.stopall)
def periodic_tasks(self, raise_on_error=False): """Tasks to be run at a periodic interval.""" ctxt = context.get_admin_context() self.manager.periodic_tasks(ctxt, raise_on_error=raise_on_error)
def _test_enforce_adminonly_attribute(self, action): admin_context = context.get_admin_context() target = {'shared': True} result = policy.enforce(admin_context, action, target) self.assertEqual(True, result)
def test_apmec_context_with_load_roles_true(self): ctx = context.get_admin_context() self.assertIn('admin', ctx.roles)
def context(self): if 'apmec.context' not in self.environ: self.environ['apmec.context'] = context.get_admin_context() return self.environ['apmec.context']
def test_apmec_context_with_load_roles_false(self): ctx = context.get_admin_context(load_admin_roles=False) self.assertFalse(ctx.roles)