Allow probe-create to specify device_owner.
The device owner of the probe port can be specified by the --device-owner option. There are two values for device-owner option, network or compute. The probe port will be created with the network as the device owner by default. Fixes: bug #1102726 Change-Id: I72d62e2fe7b8f7a5eb4411bc9052efa82fb4fdf5
This commit is contained in:
parent
71bb9359f0
commit
b1e13930d6
@ -44,12 +44,17 @@ class CreateProbe(ProbeCommand):
|
||||
parser.add_argument(
|
||||
'id', metavar='network_id',
|
||||
help=_('ID of network to probe'))
|
||||
parser.add_argument(
|
||||
'--device-owner',
|
||||
default='network', choices=['network', 'compute'],
|
||||
help=_('owner type of the device: network/compute'))
|
||||
return parser
|
||||
|
||||
def run(self, parsed_args):
|
||||
self.log.debug('run(%s)' % parsed_args)
|
||||
debug_agent = self.get_debug_agent()
|
||||
port = debug_agent.create_probe(parsed_args.id)
|
||||
port = debug_agent.create_probe(parsed_args.id,
|
||||
parsed_args.device_owner)
|
||||
self.app.stdout.write(_('Probe created : %s ') % port.id + '\n')
|
||||
|
||||
|
||||
|
@ -30,7 +30,9 @@ from quantum.openstack.common import log as logging
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
DEVICE_OWNER_PROBE = 'network:probe'
|
||||
DEVICE_OWNER_NETWORK_PROBE = 'network:probe'
|
||||
|
||||
DEVICE_OWNER_COMPUTE_PROBE = 'compute:probe'
|
||||
|
||||
|
||||
class QuantumDebugAgent():
|
||||
@ -56,13 +58,13 @@ class QuantumDebugAgent():
|
||||
def _get_namespace(self, port):
|
||||
return "qprobe-%s" % port.id
|
||||
|
||||
def create_probe(self, network_id):
|
||||
def create_probe(self, network_id, device_owner='network'):
|
||||
network = self._get_network(network_id)
|
||||
bridge = None
|
||||
if network.external:
|
||||
bridge = self.conf.external_network_bridge
|
||||
|
||||
port = self._create_port(network)
|
||||
port = self._create_port(network, device_owner)
|
||||
port.network = network
|
||||
interface_name = self.driver.get_device_name(port)
|
||||
namespace = None
|
||||
@ -100,8 +102,10 @@ class QuantumDebugAgent():
|
||||
return network
|
||||
|
||||
def clear_probe(self):
|
||||
ports = self.client.list_ports(device_id=socket.gethostname(),
|
||||
device_owner=DEVICE_OWNER_PROBE)
|
||||
ports = self.client.list_ports(
|
||||
device_id=socket.gethostname(),
|
||||
device_owner=[DEVICE_OWNER_NETWORK_PROBE,
|
||||
DEVICE_OWNER_COMPUTE_PROBE])
|
||||
info = ports['ports']
|
||||
for port in info:
|
||||
self.delete_probe(port['id'])
|
||||
@ -128,7 +132,9 @@ class QuantumDebugAgent():
|
||||
self.client.delete_port(port.id)
|
||||
|
||||
def list_probes(self):
|
||||
ports = self.client.list_ports(device_owner=DEVICE_OWNER_PROBE)
|
||||
ports = self.client.list_ports(
|
||||
device_owner=[DEVICE_OWNER_NETWORK_PROBE,
|
||||
DEVICE_OWNER_COMPUTE_PROBE])
|
||||
info = ports['ports']
|
||||
for port in info:
|
||||
port['device_name'] = self.driver.get_device_name(DictModel(port))
|
||||
@ -149,7 +155,7 @@ class QuantumDebugAgent():
|
||||
def ensure_probe(self, network_id):
|
||||
ports = self.client.list_ports(network_id=network_id,
|
||||
device_id=socket.gethostname(),
|
||||
device_owner=DEVICE_OWNER_PROBE)
|
||||
device_owner=DEVICE_OWNER_NETWORK_PROBE)
|
||||
info = ports.get('ports', [])
|
||||
if info:
|
||||
return DictModel(info[0])
|
||||
@ -164,7 +170,7 @@ class QuantumDebugAgent():
|
||||
result = ""
|
||||
for port in ports:
|
||||
probe = self.ensure_probe(port['network_id'])
|
||||
if port['device_owner'] == DEVICE_OWNER_PROBE:
|
||||
if port['device_owner'] == DEVICE_OWNER_NETWORK_PROBE:
|
||||
continue
|
||||
for fixed_ip in port['fixed_ips']:
|
||||
address = fixed_ip['ip_address']
|
||||
@ -179,12 +185,12 @@ class QuantumDebugAgent():
|
||||
address))
|
||||
return result
|
||||
|
||||
def _create_port(self, network):
|
||||
def _create_port(self, network, device_owner):
|
||||
body = dict(port=dict(
|
||||
admin_state_up=True,
|
||||
network_id=network.id,
|
||||
device_id='%s' % socket.gethostname(),
|
||||
device_owner=DEVICE_OWNER_PROBE,
|
||||
device_owner='%s:probe' % device_owner,
|
||||
tenant_id=network.tenant_id,
|
||||
fixed_ips=[dict(subnet_id=s.id) for s in network.subnets]))
|
||||
port_dict = self.client.create_port(body)['port']
|
||||
|
@ -23,7 +23,9 @@ from oslo.config import cfg
|
||||
from quantum.agent.common import config
|
||||
from quantum.agent.linux import interface
|
||||
from quantum.debug import commands
|
||||
from quantum.debug.debug_agent import DEVICE_OWNER_PROBE, QuantumDebugAgent
|
||||
from quantum.debug.debug_agent import DEVICE_OWNER_COMPUTE_PROBE
|
||||
from quantum.debug.debug_agent import DEVICE_OWNER_NETWORK_PROBE
|
||||
from quantum.debug.debug_agent import QuantumDebugAgent
|
||||
from quantum.tests import base
|
||||
|
||||
|
||||
@ -103,14 +105,17 @@ class TestDebugCommands(base.BaseTestCase):
|
||||
client_inst,
|
||||
mock_driver)
|
||||
|
||||
def test_create_probe(self):
|
||||
def _test_create_probe(self, device_owner):
|
||||
cmd = commands.CreateProbe(self.app, None)
|
||||
cmd_parser = cmd.get_parser('create_probe')
|
||||
args = ['fake_net']
|
||||
if device_owner == DEVICE_OWNER_COMPUTE_PROBE:
|
||||
args = ['fake_net', '--device-owner', 'compute']
|
||||
else:
|
||||
args = ['fake_net']
|
||||
parsed_args = cmd_parser.parse_args(args)
|
||||
cmd.run(parsed_args)
|
||||
fake_port = {'port':
|
||||
{'device_owner': DEVICE_OWNER_PROBE,
|
||||
{'device_owner': device_owner,
|
||||
'admin_state_up': True,
|
||||
'network_id': 'fake_net',
|
||||
'tenant_id': 'fake_tenant',
|
||||
@ -133,7 +138,13 @@ class TestDebugCommands(base.BaseTestCase):
|
||||
namespace=namespace
|
||||
)])
|
||||
|
||||
def test_create_probe_external(self):
|
||||
def test_create_newwork_probe(self):
|
||||
self._test_create_probe(DEVICE_OWNER_NETWORK_PROBE)
|
||||
|
||||
def test_create_nova_probe(self):
|
||||
self._test_create_probe(DEVICE_OWNER_COMPUTE_PROBE)
|
||||
|
||||
def _test_create_probe_external(self, device_owner):
|
||||
fake_network = {'network': {'id': 'fake_net',
|
||||
'tenant_id': 'fake_tenant',
|
||||
'router:external': True,
|
||||
@ -141,11 +152,14 @@ class TestDebugCommands(base.BaseTestCase):
|
||||
self.client.show_network.return_value = fake_network
|
||||
cmd = commands.CreateProbe(self.app, None)
|
||||
cmd_parser = cmd.get_parser('create_probe')
|
||||
args = ['fake_net']
|
||||
if device_owner == DEVICE_OWNER_COMPUTE_PROBE:
|
||||
args = ['fake_net', '--device-owner', 'compute']
|
||||
else:
|
||||
args = ['fake_net']
|
||||
parsed_args = cmd_parser.parse_args(args)
|
||||
cmd.run(parsed_args)
|
||||
fake_port = {'port':
|
||||
{'device_owner': DEVICE_OWNER_PROBE,
|
||||
{'device_owner': device_owner,
|
||||
'admin_state_up': True,
|
||||
'network_id': 'fake_net',
|
||||
'tenant_id': 'fake_tenant',
|
||||
@ -168,6 +182,12 @@ class TestDebugCommands(base.BaseTestCase):
|
||||
namespace=namespace
|
||||
)])
|
||||
|
||||
def test_create_network_probe_external(self):
|
||||
self._test_create_probe_external(DEVICE_OWNER_NETWORK_PROBE)
|
||||
|
||||
def test_create_nova_probe_external(self):
|
||||
self._test_create_probe_external(DEVICE_OWNER_COMPUTE_PROBE)
|
||||
|
||||
def test_delete_probe(self):
|
||||
cmd = commands.DeleteProbe(self.app, None)
|
||||
cmd_parser = cmd.get_parser('delete_probe')
|
||||
@ -227,7 +247,8 @@ class TestDebugCommands(base.BaseTestCase):
|
||||
parsed_args = cmd_parser.parse_args(args)
|
||||
cmd.run(parsed_args)
|
||||
self.client.assert_has_calls(
|
||||
[mock.call.list_ports(device_owner=DEVICE_OWNER_PROBE)])
|
||||
[mock.call.list_ports(device_owner=[DEVICE_OWNER_NETWORK_PROBE,
|
||||
DEVICE_OWNER_COMPUTE_PROBE])])
|
||||
|
||||
def test_exec_command(self):
|
||||
cmd = commands.ExecProbe(self.app, None)
|
||||
@ -257,13 +278,14 @@ class TestDebugCommands(base.BaseTestCase):
|
||||
parsed_args = cmd_parser.parse_args(args)
|
||||
cmd.run(parsed_args)
|
||||
namespace = 'qprobe-fake_port'
|
||||
self.client.assert_has_calls([mock.call.list_ports(
|
||||
device_id=socket.gethostname(),
|
||||
device_owner=DEVICE_OWNER_PROBE),
|
||||
mock.call.show_port('fake_port'),
|
||||
mock.call.show_network('fake_net'),
|
||||
mock.call.show_subnet('fake_subnet'),
|
||||
mock.call.delete_port('fake_port')])
|
||||
self.client.assert_has_calls(
|
||||
[mock.call.list_ports(device_id=socket.gethostname(),
|
||||
device_owner=[DEVICE_OWNER_NETWORK_PROBE,
|
||||
DEVICE_OWNER_COMPUTE_PROBE]),
|
||||
mock.call.show_port('fake_port'),
|
||||
mock.call.show_network('fake_net'),
|
||||
mock.call.show_subnet('fake_subnet'),
|
||||
mock.call.delete_port('fake_port')])
|
||||
self.driver.assert_has_calls([mock.call.get_device_name(mock.ANY),
|
||||
mock.call.unplug('tap12345678-12',
|
||||
namespace=namespace,
|
||||
@ -287,7 +309,7 @@ class TestDebugCommands(base.BaseTestCase):
|
||||
cmd.run(parsed_args)
|
||||
ns.assert_has_calls([mock.call.execute(mock.ANY)])
|
||||
fake_port = {'port':
|
||||
{'device_owner': DEVICE_OWNER_PROBE,
|
||||
{'device_owner': DEVICE_OWNER_NETWORK_PROBE,
|
||||
'admin_state_up': True,
|
||||
'network_id': 'fake_net',
|
||||
'tenant_id': 'fake_tenant',
|
||||
@ -312,16 +334,17 @@ class TestDebugCommands(base.BaseTestCase):
|
||||
cmd.run(parsed_args)
|
||||
ns.assert_has_calls([mock.call.execute(mock.ANY)])
|
||||
fake_port = {'port':
|
||||
{'device_owner': DEVICE_OWNER_PROBE,
|
||||
{'device_owner': DEVICE_OWNER_NETWORK_PROBE,
|
||||
'admin_state_up': True,
|
||||
'network_id': 'fake_net',
|
||||
'tenant_id': 'fake_tenant',
|
||||
'fixed_ips': [{'subnet_id': 'fake_subnet'}],
|
||||
'device_id': socket.gethostname()}}
|
||||
expected = [mock.call.list_ports(),
|
||||
mock.call.list_ports(network_id='fake_net',
|
||||
device_owner=DEVICE_OWNER_PROBE,
|
||||
device_id=socket.gethostname()),
|
||||
mock.call.list_ports(
|
||||
network_id='fake_net',
|
||||
device_owner=DEVICE_OWNER_NETWORK_PROBE,
|
||||
device_id=socket.gethostname()),
|
||||
mock.call.show_subnet('fake_subnet'),
|
||||
mock.call.show_port('fake_port')]
|
||||
self.client.assert_has_calls(expected)
|
||||
|
Loading…
Reference in New Issue
Block a user