LinuxBridge: set port status as 'DOWN' on creation
When a port is created the initial status will be 'DOWN'. The agent in turn will update the plugin of the actual port status. Change-Id: I66b51501304f7cb3f0157a4adaec4b82c62b30a3
This commit is contained in:
parent
8f28b58861
commit
200f9d53be
@ -1213,13 +1213,18 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
|
|||||||
# Returns the IP's for the port
|
# Returns the IP's for the port
|
||||||
ips = self._allocate_ips_for_port(context, network, port)
|
ips = self._allocate_ips_for_port(context, network, port)
|
||||||
|
|
||||||
|
if 'status' not in p:
|
||||||
|
status = constants.PORT_STATUS_ACTIVE
|
||||||
|
else:
|
||||||
|
status = p['status']
|
||||||
|
|
||||||
port = models_v2.Port(tenant_id=tenant_id,
|
port = models_v2.Port(tenant_id=tenant_id,
|
||||||
name=p['name'],
|
name=p['name'],
|
||||||
id=port_id,
|
id=port_id,
|
||||||
network_id=network_id,
|
network_id=network_id,
|
||||||
mac_address=mac_address,
|
mac_address=mac_address,
|
||||||
admin_state_up=p['admin_state_up'],
|
admin_state_up=p['admin_state_up'],
|
||||||
status=constants.PORT_STATUS_ACTIVE,
|
status=status,
|
||||||
device_id=p['device_id'],
|
device_id=p['device_id'],
|
||||||
device_owner=p['device_owner'])
|
device_owner=p['device_owner'])
|
||||||
context.session.add(port)
|
context.session.add(port)
|
||||||
|
@ -481,6 +481,9 @@ class LinuxBridgePluginV2(db_base_plugin_v2.QuantumDbPluginV2,
|
|||||||
with session.begin(subtransactions=True):
|
with session.begin(subtransactions=True):
|
||||||
self._ensure_default_security_group_on_port(context, port)
|
self._ensure_default_security_group_on_port(context, port)
|
||||||
sgids = self._get_security_groups_on_port(context, port)
|
sgids = self._get_security_groups_on_port(context, port)
|
||||||
|
# Set port status as 'DOWN'. This will be updated by agent
|
||||||
|
port['port']['status'] = q_const.PORT_STATUS_DOWN
|
||||||
|
|
||||||
port = super(LinuxBridgePluginV2,
|
port = super(LinuxBridgePluginV2,
|
||||||
self).create_port(context, port)
|
self).create_port(context, port)
|
||||||
self._process_port_create_security_group(
|
self._process_port_create_security_group(
|
||||||
|
@ -26,6 +26,7 @@ class LinuxBridgePluginV2TestCase(test_plugin.QuantumDbPluginV2TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(LinuxBridgePluginV2TestCase, self).setUp(PLUGIN_NAME)
|
super(LinuxBridgePluginV2TestCase, self).setUp(PLUGIN_NAME)
|
||||||
|
self.port_create_status = 'DOWN'
|
||||||
|
|
||||||
|
|
||||||
class TestLinuxBridgeBasicGet(test_plugin.TestBasicGet,
|
class TestLinuxBridgeBasicGet(test_plugin.TestBasicGet,
|
||||||
@ -45,6 +46,11 @@ class TestLinuxBridgePortsV2(test_plugin.TestPortsV2,
|
|||||||
VIF_TYPE = portbindings.VIF_TYPE_BRIDGE
|
VIF_TYPE = portbindings.VIF_TYPE_BRIDGE
|
||||||
HAS_PORT_FILTER = True
|
HAS_PORT_FILTER = True
|
||||||
|
|
||||||
|
def test_update_port_status_build(self):
|
||||||
|
with self.port() as port:
|
||||||
|
self.assertEqual(port['port']['status'], 'DOWN')
|
||||||
|
self.assertEqual(self.port_create_status, 'DOWN')
|
||||||
|
|
||||||
|
|
||||||
class TestLinuxBridgeNetworksV2(test_plugin.TestNetworksV2,
|
class TestLinuxBridgeNetworksV2(test_plugin.TestNetworksV2,
|
||||||
LinuxBridgePluginV2TestCase):
|
LinuxBridgePluginV2TestCase):
|
||||||
|
@ -103,6 +103,8 @@ class QuantumDbPluginV2TestCase(unittest2.TestCase):
|
|||||||
cfg.CONF.set_override('max_dns_nameservers', 2)
|
cfg.CONF.set_override('max_dns_nameservers', 2)
|
||||||
cfg.CONF.set_override('max_subnet_host_routes', 2)
|
cfg.CONF.set_override('max_subnet_host_routes', 2)
|
||||||
self.api = APIRouter()
|
self.api = APIRouter()
|
||||||
|
# Set the defualt port status
|
||||||
|
self.port_create_status = 'ACTIVE'
|
||||||
|
|
||||||
def _is_native_bulk_supported():
|
def _is_native_bulk_supported():
|
||||||
plugin_obj = QuantumManager.get_plugin()
|
plugin_obj = QuantumManager.get_plugin()
|
||||||
@ -616,7 +618,7 @@ class TestV2HTTPResponse(QuantumDbPluginV2TestCase):
|
|||||||
|
|
||||||
class TestPortsV2(QuantumDbPluginV2TestCase):
|
class TestPortsV2(QuantumDbPluginV2TestCase):
|
||||||
def test_create_port_json(self):
|
def test_create_port_json(self):
|
||||||
keys = [('admin_state_up', True), ('status', 'ACTIVE')]
|
keys = [('admin_state_up', True), ('status', self.port_create_status)]
|
||||||
with self.port(name='myname') as port:
|
with self.port(name='myname') as port:
|
||||||
for k, v in keys:
|
for k, v in keys:
|
||||||
self.assertEqual(port['port'][k], v)
|
self.assertEqual(port['port'][k], v)
|
||||||
@ -640,7 +642,7 @@ class TestPortsV2(QuantumDbPluginV2TestCase):
|
|||||||
self.assertEqual(res.status_int, 403)
|
self.assertEqual(res.status_int, 403)
|
||||||
|
|
||||||
def test_create_port_public_network(self):
|
def test_create_port_public_network(self):
|
||||||
keys = [('admin_state_up', True), ('status', 'ACTIVE')]
|
keys = [('admin_state_up', True), ('status', self.port_create_status)]
|
||||||
with self.network(shared=True) as network:
|
with self.network(shared=True) as network:
|
||||||
port_res = self._create_port('json',
|
port_res = self._create_port('json',
|
||||||
network['network']['id'],
|
network['network']['id'],
|
||||||
@ -656,7 +658,8 @@ class TestPortsV2(QuantumDbPluginV2TestCase):
|
|||||||
def test_create_port_public_network_with_ip(self):
|
def test_create_port_public_network_with_ip(self):
|
||||||
with self.network(shared=True) as network:
|
with self.network(shared=True) as network:
|
||||||
with self.subnet(network=network, cidr='10.0.0.0/24') as subnet:
|
with self.subnet(network=network, cidr='10.0.0.0/24') as subnet:
|
||||||
keys = [('admin_state_up', True), ('status', 'ACTIVE'),
|
keys = [('admin_state_up', True),
|
||||||
|
('status', self.port_create_status),
|
||||||
('fixed_ips', [{'subnet_id': subnet['subnet']['id'],
|
('fixed_ips', [{'subnet_id': subnet['subnet']['id'],
|
||||||
'ip_address': '10.0.0.2'}])]
|
'ip_address': '10.0.0.2'}])]
|
||||||
port_res = self._create_port('json',
|
port_res = self._create_port('json',
|
||||||
|
Loading…
Reference in New Issue
Block a user