def update_network_precommit(self, context): if context.original['name'] != context.current['name']: nsx_switch_ids = nsx_utils.get_nsx_switch_ids( context._plugin_context.session, self.cluster, context.current['id'] ) if not nsx_switch_ids or len(nsx_switch_ids) < 1: LOG.warn(_("Unable to find NSX mappings for neutron " "network:%s"), context.original['id']) try: switchlib.update_lswitch( self.cluster, lswitch_ids[0], context.current['name'] ) except api_exc.NsxApiException as e: LOG.warn(_("Logical switch update on NSX backend failed. " "Neutron network id:%(net_id)s; " "NSX lswitch id:%(lswitch_id)s;" "Error:%(error)s"), {'net_id': context.current['id'], 'lswitch_id': lswitch_ids[0], 'error': e})
def test_update_lswitch(self): new_name = 'new-name' new_tags = [{'scope': 'new_tag', 'tag': 'xxx'}] transport_zones_config = [{'zone_uuid': _uuid(), 'transport_type': 'stt'}] lswitch = switchlib.create_lswitch(self.fake_cluster, _uuid(), 'pippo', 'fake-switch', transport_zones_config) switchlib.update_lswitch(self.fake_cluster, lswitch['uuid'], new_name, tags=new_tags) res_lswitch = switchlib.get_lswitches(self.fake_cluster, lswitch['uuid']) self.assertEqual(len(res_lswitch), 1) self.assertEqual(res_lswitch[0]['display_name'], new_name) switch_tags = self._build_tag_dict(res_lswitch[0]['tags']) self.assertIn('new_tag', switch_tags) self.assertEqual(switch_tags['new_tag'], 'xxx')
def _test_update_lswitch(self, tenant_id, name, tags): transport_zones_config = [{'zone_uuid': _uuid(), 'transport_type': 'stt'}] lswitch = switchlib.create_lswitch(self.fake_cluster, _uuid(), 'pippo', 'fake-switch', transport_zones_config) switchlib.update_lswitch(self.fake_cluster, lswitch['uuid'], name, tenant_id=tenant_id, tags=tags) res_lswitch = switchlib.get_lswitches(self.fake_cluster, lswitch['uuid']) self.assertEqual(len(res_lswitch), 1) self.assertEqual(res_lswitch[0]['display_name'], name) if not tags: # no need to validate tags return switch_tags = self._build_tag_dict(res_lswitch[0]['tags']) for tag in tags: self.assertIn(tag['scope'], switch_tags) self.assertEqual(tag['tag'], switch_tags[tag['scope']])
def _test_update_lswitch(self, tenant_id, name, tags): transport_zones_config = [{ 'zone_uuid': _uuid(), 'transport_type': 'stt' }] lswitch = switchlib.create_lswitch(self.fake_cluster, _uuid(), 'pippo', 'fake-switch', transport_zones_config) switchlib.update_lswitch(self.fake_cluster, lswitch['uuid'], name, tenant_id=tenant_id, tags=tags) res_lswitch = switchlib.get_lswitches(self.fake_cluster, lswitch['uuid']) self.assertEqual(len(res_lswitch), 1) self.assertEqual(res_lswitch[0]['display_name'], name) if not tags: # no need to validate tags return switch_tags = self._build_tag_dict(res_lswitch[0]['tags']) for tag in tags: self.assertIn(tag['scope'], switch_tags) self.assertEqual(tag['tag'], switch_tags[tag['scope']])