def run(self, context, job_name, readonly=False): self.results = {} if context.is_admin: if self.email_notifier: self.email_notifier.start('Cloud Housekeeper Execution Report') with locking.LockManager.get_lock('nsx-housekeeper'): error_count = 0 fixed_count = 0 error_info = '' if job_name == ALL_DUMMY_JOB_NAME: if (not readonly and not self.readwrite_allowed(ALL_DUMMY_JOB_NAME)): raise n_exc.ObjectNotFound(id=ALL_DUMMY_JOB_NAME) for job in self.jobs.values(): if (not readonly and not self.readwrite_allowed(job.get_name())): # skip this job as it is readonly continue result = job.run(context, readonly=readonly) if result: if self.email_notifier and result['error_count']: self._add_job_text_to_notifier(job, result) error_count += result['error_count'] fixed_count += result['fixed_count'] error_info += result['error_info'] + "\n" self.results[job_name] = { 'error_count': error_count, 'fixed_count': fixed_count, 'error_info': error_info } else: job = self.jobs.get(job_name) if job: if (not readonly and not self.readwrite_allowed(job_name)): raise n_exc.ObjectNotFound(id=job_name) result = job.run(context, readonly=readonly) if result: error_count = result['error_count'] if self.email_notifier: self._add_job_text_to_notifier(job, result) self.results[job.get_name()] = result else: raise n_exc.ObjectNotFound(id=job_name) if self.email_notifier and error_count: self.email_notifier.send() else: raise n_exc.AdminRequired()
def test_db_migration_with_pb_not_found(self): vif_details_list = [ { pb.CAP_PORT_FILTER: "true", pb.OVS_HYBRID_PLUG: "true", pb.VIF_DETAILS_BRIDGE_NAME: "foo", pb.VIF_DETAILS_CONNECTIVITY: "l2" }, { pb.CAP_PORT_FILTER: "true", pb.VIF_DETAILS_BRIDGE_NAME: "foo" }, { "foo": "bar" }, {}, ] self._create_ml2_ovs_test_resources(vif_details_list) with mock.patch.object( port_obj.PortBinding, 'update', side_effect=exceptions.ObjectNotFound(id='foo')): with mock.patch.object(trunk_obj.Trunk, 'get_objects', return_value=[]): db_migration.migrate_neutron_database_to_ovn( self.mech_driver._plugin) self._validate_resources_after_migration(vif_details_list)
def get(self, job_name): if job_name == ALL_DUMMY_JOB_NAME: return {'name': job_name, 'description': ALL_DUMMY_JOB['description'], 'enabled': job_name in self.jobs, 'error_count': self.results.get( job_name, {}).get('error_count', 0), 'fixed_count': self.results.get( job_name, {}).get('fixed_count', 0), 'error_info': self.results.get( job_name, {}).get('error_info', '')} for job in self: name = job.obj.get_name() if job_name == name: return {'name': job_name, 'description': job.obj.get_description(), 'enabled': job_name in self.jobs, 'error_count': self.results.get( job_name, {}).get('error_count', 0), 'fixed_count': self.results.get( job_name, {}).get('fixed_count', 0), 'error_info': self.results.get( job_name, {}).get('error_info', '')} raise n_exc.ObjectNotFound(id=job_name)
def _get_project_mapping(self, context, project_id): mapping = nsx_db.get_project_plugin_mapping( context.session, project_id) if mapping: return mapping['plugin'] else: raise exceptions.ObjectNotFound(id=project_id)
def _safe_get_object(context, model, **kwargs): db_obj = get_object(context, model, **kwargs) if db_obj is None: key = "".join( ['%s:: %s ' % (key, value) for (key, value) in kwargs.items()]) raise n_exc.ObjectNotFound(id=key) return db_obj
def get_project_mapping(context, project_id): """Return the plugin associated with this project""" mapping = nsx_db.get_project_plugin_mapping( context.session, project_id) if mapping: return mapping['plugin'] else: raise exceptions.ObjectNotFound(id=project_id)
def _safe_get_object(context, model, **kwargs): db_obj = get_object(context, model, **kwargs) if db_obj is None: key = ", ".join( ['%s=%s' % (key, value) for (key, value) in kwargs.items()]) raise n_exc.ObjectNotFound(id="%s(%s)" % (model.__name__, key)) return db_obj
def test_create_trunk_port_db_exception(self): self.trunk_1.sub_ports = [self.sub_port_1] self.mock_update_pb.side_effect = [n_exc.ObjectNotFound(id=1)] self.handler.trunk_created(self.trunk_1) self.mock_update_pb.assert_called_once_with( mock.ANY, {'profile': {'parent_name': self.sub_port_1.trunk_id, 'tag': self.sub_port_1.segmentation_id}}, host='foo.com', port_id=self.sub_port_1.port_id) self.plugin_driver._nb_ovn.set_lswitch_port.assert_not_called()
def test_delete_trunk_port_db_exception(self): self.trunk_1.sub_ports = [self.sub_port_1] self.mock_update_pb.side_effect = [n_exc.ObjectNotFound(id=1)] self.handler.trunk_deleted(self.trunk_1) self.mock_update_pb.assert_called_once_with( mock.ANY, {'profile': {}, 'vif_type': portbindings.VIF_TYPE_UNBOUND, 'host': '', 'vif_details': ''}, host='foo.com', port_id=self.sub_port_1.port_id) self.plugin_driver._nb_ovn.set_lswitch_port.assert_not_called() self.mock_clear_levels.assert_not_called()
def get(self, job_name): if job_name == ALL_DUMMY_JOB.get('name'): return ALL_DUMMY_JOB for job in self: name = job.obj.get_name() if job_name == name: return {'name': job_name, 'description': job.obj.get_description(), 'enabled': job_name in self.jobs} raise n_exc.ObjectNotFound(id=job_name)
def run(self, context, job_name): if context.is_admin: with locking.LockManager.get_lock('nsx-housekeeper'): if job_name == ALL_DUMMY_JOB.get('name'): for job in self.jobs.values(): job.run(context) else: job = self.jobs.get(job_name) if job: job.run(context) else: raise n_exc.ObjectNotFound(id=job_name) else: raise n_exc.AdminRequired()
def test_secgroup_create_with_illegal_policy(self): policy_id = 'bad-policy' with mock.patch(PLUGIN_NAME + '.get_nsx_policy', side_effect=n_exc.ObjectNotFound(id=policy_id)): res = self._create_secgroup_with_policy(policy_id) self.assertEqual(400, res.status_int)
def get_project_plugin_map(self, context, id, fields=None): data = nsx_db.get_project_plugin_mapping(context.session, id) if data: return self._get_project_plugin_dict(data) else: raise n_exc.ObjectNotFound(id=id)
def _safe_get_object(context, model, id, key='id'): db_obj = get_object(context, model, **{key: id}) if db_obj is None: raise n_exc.ObjectNotFound(id=id) return db_obj