def _format_commands(self, commands, **kwargs): if not commands: return [] if not all(kwargs.values()): raise exc.GenericSwitchNetmikoMethodError(cmds=commands, args=kwargs) try: cmd_set = [cmd.format(**kwargs) for cmd in commands] except (KeyError, TypeError): raise exc.GenericSwitchNetmikoMethodError(cmds=commands, args=kwargs) return cmd_set
def test_delete_port_postcommit_failure(self, m_list): driver = gsm.GenericSwitchDriver() driver.initialize() mock_context = mock.create_autospec(driver_context.PortContext) self.switch_mock.delete_port.side_effect = ( exceptions.GenericSwitchNetmikoMethodError(cmds='foo', args='bar')) mock_context.current = {'binding:profile': {'local_link_information': [ { 'switch_info': 'foo', 'port_id': '2222' } ] }, 'binding:vnic_type': 'baremetal', 'binding:vif_type': 'other', 'id': 'aaaa-bbbb-cccc'} mock_context.network = mock.Mock() mock_context.network.current = {'provider:segmentation_id': 123, 'id': 'aaaa-bbbb-cccc'} mock_context.segments_to_bind = [mock_context.network.current] self.assertRaises(exceptions.GenericSwitchNetmikoMethodError, driver.delete_port_postcommit, mock_context)