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
9951582d33
commit
1d206cc309
@ -44,12 +44,17 @@ class CreateProbe(ProbeCommand):
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'id', metavar='network_id',
|
'id', metavar='network_id',
|
||||||
help=_('ID of network to probe'))
|
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
|
return parser
|
||||||
|
|
||||||
def run(self, parsed_args):
|
def run(self, parsed_args):
|
||||||
self.log.debug('run(%s)' % parsed_args)
|
self.log.debug('run(%s)' % parsed_args)
|
||||||
debug_agent = self.get_debug_agent()
|
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')
|
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__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
DEVICE_OWNER_PROBE = 'network:probe'
|
DEVICE_OWNER_NETWORK_PROBE = 'network:probe'
|
||||||
|
|
||||||
|
DEVICE_OWNER_COMPUTE_PROBE = 'compute:probe'
|
||||||
|
|
||||||
|
|
||||||
class QuantumDebugAgent():
|
class QuantumDebugAgent():
|
||||||
@ -56,13 +58,13 @@ class QuantumDebugAgent():
|
|||||||
def _get_namespace(self, port):
|
def _get_namespace(self, port):
|
||||||
return "qprobe-%s" % port.id
|
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)
|
network = self._get_network(network_id)
|
||||||
bridge = None
|
bridge = None
|
||||||
if network.external:
|
if network.external:
|
||||||
bridge = self.conf.external_network_bridge
|
bridge = self.conf.external_network_bridge
|
||||||
|
|
||||||
port = self._create_port(network)
|
port = self._create_port(network, device_owner)
|
||||||
port.network = network
|
port.network = network
|
||||||
interface_name = self.driver.get_device_name(port)
|
interface_name = self.driver.get_device_name(port)
|
||||||
namespace = None
|
namespace = None
|
||||||
@ -100,8 +102,10 @@ class QuantumDebugAgent():
|
|||||||
return network
|
return network
|
||||||
|
|
||||||
def clear_probe(self):
|
def clear_probe(self):
|
||||||
ports = self.client.list_ports(device_id=socket.gethostname(),
|
ports = self.client.list_ports(
|
||||||
device_owner=DEVICE_OWNER_PROBE)
|
device_id=socket.gethostname(),
|
||||||
|
device_owner=[DEVICE_OWNER_NETWORK_PROBE,
|
||||||
|
DEVICE_OWNER_COMPUTE_PROBE])
|
||||||
info = ports['ports']
|
info = ports['ports']
|
||||||
for port in info:
|
for port in info:
|
||||||
self.delete_probe(port['id'])
|
self.delete_probe(port['id'])
|
||||||
@ -128,7 +132,9 @@ class QuantumDebugAgent():
|
|||||||
self.client.delete_port(port.id)
|
self.client.delete_port(port.id)
|
||||||
|
|
||||||
def list_probes(self):
|
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']
|
info = ports['ports']
|
||||||
for port in info:
|
for port in info:
|
||||||
port['device_name'] = self.driver.get_device_name(DictModel(port))
|
port['device_name'] = self.driver.get_device_name(DictModel(port))
|
||||||
@ -149,7 +155,7 @@ class QuantumDebugAgent():
|
|||||||
def ensure_probe(self, network_id):
|
def ensure_probe(self, network_id):
|
||||||
ports = self.client.list_ports(network_id=network_id,
|
ports = self.client.list_ports(network_id=network_id,
|
||||||
device_id=socket.gethostname(),
|
device_id=socket.gethostname(),
|
||||||
device_owner=DEVICE_OWNER_PROBE)
|
device_owner=DEVICE_OWNER_NETWORK_PROBE)
|
||||||
info = ports.get('ports', [])
|
info = ports.get('ports', [])
|
||||||
if info:
|
if info:
|
||||||
return DictModel(info[0])
|
return DictModel(info[0])
|
||||||
@ -164,7 +170,7 @@ class QuantumDebugAgent():
|
|||||||
result = ""
|
result = ""
|
||||||
for port in ports:
|
for port in ports:
|
||||||
probe = self.ensure_probe(port['network_id'])
|
probe = self.ensure_probe(port['network_id'])
|
||||||
if port['device_owner'] == DEVICE_OWNER_PROBE:
|
if port['device_owner'] == DEVICE_OWNER_NETWORK_PROBE:
|
||||||
continue
|
continue
|
||||||
for fixed_ip in port['fixed_ips']:
|
for fixed_ip in port['fixed_ips']:
|
||||||
address = fixed_ip['ip_address']
|
address = fixed_ip['ip_address']
|
||||||
@ -179,12 +185,12 @@ class QuantumDebugAgent():
|
|||||||
address))
|
address))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def _create_port(self, network):
|
def _create_port(self, network, device_owner):
|
||||||
body = dict(port=dict(
|
body = dict(port=dict(
|
||||||
admin_state_up=True,
|
admin_state_up=True,
|
||||||
network_id=network.id,
|
network_id=network.id,
|
||||||
device_id='%s' % socket.gethostname(),
|
device_id='%s' % socket.gethostname(),
|
||||||
device_owner=DEVICE_OWNER_PROBE,
|
device_owner='%s:probe' % device_owner,
|
||||||
tenant_id=network.tenant_id,
|
tenant_id=network.tenant_id,
|
||||||
fixed_ips=[dict(subnet_id=s.id) for s in network.subnets]))
|
fixed_ips=[dict(subnet_id=s.id) for s in network.subnets]))
|
||||||
port_dict = self.client.create_port(body)['port']
|
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.common import config
|
||||||
from quantum.agent.linux import interface
|
from quantum.agent.linux import interface
|
||||||
from quantum.debug import commands
|
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
|
from quantum.tests import base
|
||||||
|
|
||||||
|
|
||||||
@ -103,14 +105,17 @@ class TestDebugCommands(base.BaseTestCase):
|
|||||||
client_inst,
|
client_inst,
|
||||||
mock_driver)
|
mock_driver)
|
||||||
|
|
||||||
def test_create_probe(self):
|
def _test_create_probe(self, device_owner):
|
||||||
cmd = commands.CreateProbe(self.app, None)
|
cmd = commands.CreateProbe(self.app, None)
|
||||||
cmd_parser = cmd.get_parser('create_probe')
|
cmd_parser = cmd.get_parser('create_probe')
|
||||||
|
if device_owner == DEVICE_OWNER_COMPUTE_PROBE:
|
||||||
|
args = ['fake_net', '--device-owner', 'compute']
|
||||||
|
else:
|
||||||
args = ['fake_net']
|
args = ['fake_net']
|
||||||
parsed_args = cmd_parser.parse_args(args)
|
parsed_args = cmd_parser.parse_args(args)
|
||||||
cmd.run(parsed_args)
|
cmd.run(parsed_args)
|
||||||
fake_port = {'port':
|
fake_port = {'port':
|
||||||
{'device_owner': DEVICE_OWNER_PROBE,
|
{'device_owner': device_owner,
|
||||||
'admin_state_up': True,
|
'admin_state_up': True,
|
||||||
'network_id': 'fake_net',
|
'network_id': 'fake_net',
|
||||||
'tenant_id': 'fake_tenant',
|
'tenant_id': 'fake_tenant',
|
||||||
@ -133,7 +138,13 @@ class TestDebugCommands(base.BaseTestCase):
|
|||||||
namespace=namespace
|
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',
|
fake_network = {'network': {'id': 'fake_net',
|
||||||
'tenant_id': 'fake_tenant',
|
'tenant_id': 'fake_tenant',
|
||||||
'router:external': True,
|
'router:external': True,
|
||||||
@ -141,11 +152,14 @@ class TestDebugCommands(base.BaseTestCase):
|
|||||||
self.client.show_network.return_value = fake_network
|
self.client.show_network.return_value = fake_network
|
||||||
cmd = commands.CreateProbe(self.app, None)
|
cmd = commands.CreateProbe(self.app, None)
|
||||||
cmd_parser = cmd.get_parser('create_probe')
|
cmd_parser = cmd.get_parser('create_probe')
|
||||||
|
if device_owner == DEVICE_OWNER_COMPUTE_PROBE:
|
||||||
|
args = ['fake_net', '--device-owner', 'compute']
|
||||||
|
else:
|
||||||
args = ['fake_net']
|
args = ['fake_net']
|
||||||
parsed_args = cmd_parser.parse_args(args)
|
parsed_args = cmd_parser.parse_args(args)
|
||||||
cmd.run(parsed_args)
|
cmd.run(parsed_args)
|
||||||
fake_port = {'port':
|
fake_port = {'port':
|
||||||
{'device_owner': DEVICE_OWNER_PROBE,
|
{'device_owner': device_owner,
|
||||||
'admin_state_up': True,
|
'admin_state_up': True,
|
||||||
'network_id': 'fake_net',
|
'network_id': 'fake_net',
|
||||||
'tenant_id': 'fake_tenant',
|
'tenant_id': 'fake_tenant',
|
||||||
@ -168,6 +182,12 @@ class TestDebugCommands(base.BaseTestCase):
|
|||||||
namespace=namespace
|
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):
|
def test_delete_probe(self):
|
||||||
cmd = commands.DeleteProbe(self.app, None)
|
cmd = commands.DeleteProbe(self.app, None)
|
||||||
cmd_parser = cmd.get_parser('delete_probe')
|
cmd_parser = cmd.get_parser('delete_probe')
|
||||||
@ -227,7 +247,8 @@ class TestDebugCommands(base.BaseTestCase):
|
|||||||
parsed_args = cmd_parser.parse_args(args)
|
parsed_args = cmd_parser.parse_args(args)
|
||||||
cmd.run(parsed_args)
|
cmd.run(parsed_args)
|
||||||
self.client.assert_has_calls(
|
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):
|
def test_exec_command(self):
|
||||||
cmd = commands.ExecProbe(self.app, None)
|
cmd = commands.ExecProbe(self.app, None)
|
||||||
@ -257,9 +278,10 @@ class TestDebugCommands(base.BaseTestCase):
|
|||||||
parsed_args = cmd_parser.parse_args(args)
|
parsed_args = cmd_parser.parse_args(args)
|
||||||
cmd.run(parsed_args)
|
cmd.run(parsed_args)
|
||||||
namespace = 'qprobe-fake_port'
|
namespace = 'qprobe-fake_port'
|
||||||
self.client.assert_has_calls([mock.call.list_ports(
|
self.client.assert_has_calls(
|
||||||
device_id=socket.gethostname(),
|
[mock.call.list_ports(device_id=socket.gethostname(),
|
||||||
device_owner=DEVICE_OWNER_PROBE),
|
device_owner=[DEVICE_OWNER_NETWORK_PROBE,
|
||||||
|
DEVICE_OWNER_COMPUTE_PROBE]),
|
||||||
mock.call.show_port('fake_port'),
|
mock.call.show_port('fake_port'),
|
||||||
mock.call.show_network('fake_net'),
|
mock.call.show_network('fake_net'),
|
||||||
mock.call.show_subnet('fake_subnet'),
|
mock.call.show_subnet('fake_subnet'),
|
||||||
@ -287,7 +309,7 @@ class TestDebugCommands(base.BaseTestCase):
|
|||||||
cmd.run(parsed_args)
|
cmd.run(parsed_args)
|
||||||
ns.assert_has_calls([mock.call.execute(mock.ANY)])
|
ns.assert_has_calls([mock.call.execute(mock.ANY)])
|
||||||
fake_port = {'port':
|
fake_port = {'port':
|
||||||
{'device_owner': DEVICE_OWNER_PROBE,
|
{'device_owner': DEVICE_OWNER_NETWORK_PROBE,
|
||||||
'admin_state_up': True,
|
'admin_state_up': True,
|
||||||
'network_id': 'fake_net',
|
'network_id': 'fake_net',
|
||||||
'tenant_id': 'fake_tenant',
|
'tenant_id': 'fake_tenant',
|
||||||
@ -312,15 +334,16 @@ class TestDebugCommands(base.BaseTestCase):
|
|||||||
cmd.run(parsed_args)
|
cmd.run(parsed_args)
|
||||||
ns.assert_has_calls([mock.call.execute(mock.ANY)])
|
ns.assert_has_calls([mock.call.execute(mock.ANY)])
|
||||||
fake_port = {'port':
|
fake_port = {'port':
|
||||||
{'device_owner': DEVICE_OWNER_PROBE,
|
{'device_owner': DEVICE_OWNER_NETWORK_PROBE,
|
||||||
'admin_state_up': True,
|
'admin_state_up': True,
|
||||||
'network_id': 'fake_net',
|
'network_id': 'fake_net',
|
||||||
'tenant_id': 'fake_tenant',
|
'tenant_id': 'fake_tenant',
|
||||||
'fixed_ips': [{'subnet_id': 'fake_subnet'}],
|
'fixed_ips': [{'subnet_id': 'fake_subnet'}],
|
||||||
'device_id': socket.gethostname()}}
|
'device_id': socket.gethostname()}}
|
||||||
expected = [mock.call.list_ports(),
|
expected = [mock.call.list_ports(),
|
||||||
mock.call.list_ports(network_id='fake_net',
|
mock.call.list_ports(
|
||||||
device_owner=DEVICE_OWNER_PROBE,
|
network_id='fake_net',
|
||||||
|
device_owner=DEVICE_OWNER_NETWORK_PROBE,
|
||||||
device_id=socket.gethostname()),
|
device_id=socket.gethostname()),
|
||||||
mock.call.show_subnet('fake_subnet'),
|
mock.call.show_subnet('fake_subnet'),
|
||||||
mock.call.show_port('fake_port')]
|
mock.call.show_port('fake_port')]
|
||||||
|
Loading…
Reference in New Issue
Block a user