Skip to content

Commit

Permalink
Get noop drivers to function within flows
Browse files Browse the repository at this point in the history
The noop drivers suffered from not being updated and just not being tested
with being called within flows like normal real op drivers.  This gets the noop
drivers to succeed when called liked other drivers.  They do not do anything
and will return fake information whenever it is required they return data.
This can be improved later so that they actually do their own data store, but
that would require a much larger update and I'm not sure there's much value
in it.

Change-Id: I2627ed35c0f576f8cfa258b542e5bdb4be03dac8
Closes-Bug: #1501190
  • Loading branch information
Brandon Logan committed Sep 30, 2015
1 parent a474130 commit 0c80a3b
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 33 deletions.
13 changes: 7 additions & 6 deletions octavia/amphorae/drivers/noop_driver/driver.py
Expand Up @@ -80,10 +80,11 @@ def finalize_amphora(self, amphora):
self.__class__.__name__, amphora.id)
self.amphoraconfig[amphora.id] = (amphora.id, 'finalize amphora')

def post_network_plug(self, amphora):
LOG.debug("Amphora %s no-op, post network plug amphora %s",
self.__class__.__name__, amphora.id)
self.amphoraconfig[amphora.id] = (amphora.id, 'post_network_plug')
def post_network_plug(self, amphora, port):
LOG.debug("Amphora %s no-op, post network plug amphora %s, port %s",
self.__class__.__name__, amphora.id, port.id)
self.amphoraconfig[amphora.id, port.id] = (amphora.id, port.id,
'post_network_plug')

def post_vip_plug(self, load_balancer, amphorae_network_config):
LOG.debug("Amphora %s no-op, post vip plug load balancer %s",
Expand Down Expand Up @@ -125,9 +126,9 @@ def finalize_amphora(self, amphora):

self.driver.finalize_amphora(amphora)

def post_network_plug(self, amphora):
def post_network_plug(self, amphora, port):

self.driver.post_network_plug(amphora)
self.driver.post_network_plug(amphora, port)

def post_vip_plug(self, load_balancer, amphorae_network_config):

Expand Down
40 changes: 26 additions & 14 deletions octavia/compute/drivers/noop_driver/driver.py
Expand Up @@ -13,7 +13,10 @@
# under the License.

from oslo_log import log as logging
from oslo_utils import uuidutils

from octavia.common import constants
from octavia.common import data_models
from octavia.compute import compute_base as driver_base

LOG = logging.getLogger(__name__)
Expand All @@ -26,19 +29,21 @@ def __init__(self):

def build(self, name="amphora_name", amphora_flavor=None, image_id=None,
key_name=None, sec_groups=None, network_ids=None,
config_drive_files=None, user_data=None):
config_drive_files=None, user_data=None, port_ids=None):
LOG.debug("Compute %s no-op, build name %s, amphora_flavor %s, "
"image_id %s, key_name %s, sec_groups %s, network_ids %s,"
"config_drive_files %s, user_data %s",
"config_drive_files %s, user_data %s, port_ids %s",
self.__class__.__name__, name, amphora_flavor, image_id,
key_name, sec_groups, network_ids, config_drive_files,
user_data)
user_data, port_ids)
self.computeconfig[(name, amphora_flavor, image_id, key_name,
sec_groups, network_ids, config_drive_files,
user_data)] = (name, amphora_flavor,
image_id, key_name, sec_groups,
network_ids, config_drive_files,
user_data, 'build')
user_data)] = (
name, amphora_flavor,
image_id, key_name, sec_groups,
network_ids, config_drive_files,
user_data, port_ids, 'build')
compute_id = uuidutils.generate_uuid()
return compute_id

def delete(self, amphora_id):
LOG.debug("Compute %s no-op, amphora_id %s",
Expand All @@ -49,11 +54,17 @@ def status(self, amphora_id):
LOG.debug("Compute %s no-op, amphora_id %s",
self.__class__.__name__, amphora_id)
self.computeconfig[amphora_id] = (amphora_id, 'status')
return constants.UP

def get_amphora(self, amphora_id):
LOG.debug("Compute %s no-op, amphora_id %s",
self.__class__.__name__, amphora_id)
self.computeconfig[amphora_id] = (amphora_id, 'get_amphora')
return data_models.Amphora(
compute_id=amphora_id,
status=constants.ACTIVE,
lb_network_ip='192.0.2.1'
)


class NoopComputeDriver(driver_base.ComputeBase):
Expand All @@ -63,17 +74,18 @@ def __init__(self, region=None):

def build(self, name="amphora_name", amphora_flavor=None, image_id=None,
key_name=None, sec_groups=None, network_ids=None,
config_drive_files=None, user_data=None):
config_drive_files=None, user_data=None, port_ids=None):

self.driver.build(name, amphora_flavor, image_id, key_name,
sec_groups, network_ids, config_drive_files,
user_data)
compute_id = self.driver.build(name, amphora_flavor, image_id,
key_name, sec_groups, network_ids,
config_drive_files, user_data, port_ids)
return compute_id

def delete(self, amphora_id):
self.driver.delete(amphora_id)

def status(self, amphora_id):
self.driver.status(amphora_id)
return self.driver.status(amphora_id)

def get_amphora(self, amphora_id):
self.driver.get_amphora(amphora_id)
return self.driver.get_amphora(amphora_id)
2 changes: 1 addition & 1 deletion octavia/controller/worker/tasks/compute_tasks.py
Expand Up @@ -125,7 +125,7 @@ class DeleteAmphoraeOnLoadBalancer(BaseComputeTask):
def execute(self, loadbalancer):
for amp in loadbalancer.amphorae:
try:
self.compute.delete(compute_id=amp.compute_id)
self.compute.delete(amp.compute_id)
except Exception as e:
LOG.error(_LE("Nova delete for amphora id: %(amp)s failed:"
"%(exp)s"), {'amp': amp.id, 'exp': e})
Expand Down
43 changes: 36 additions & 7 deletions octavia/network/drivers/noop_driver/driver.py
Expand Up @@ -13,8 +13,11 @@
# under the License.

from oslo_log import log as logging
from oslo_utils import uuidutils

from octavia.common import data_models
from octavia.network import base as driver_base
from octavia.network import data_models as network_models

LOG = logging.getLogger(__name__)

Expand All @@ -29,6 +32,10 @@ def allocate_vip(self, load_balancer):
self.__class__.__name__, load_balancer)
self.networkconfigconfig[load_balancer] = (
load_balancer, 'allocate_vip')
return data_models.Vip(ip_address='198.51.100.1',
subnet_id=uuidutils.generate_uuid(),
port_id=uuidutils.generate_uuid(),
load_balancer_id=load_balancer.id)

def deallocate_vip(self, vip):
LOG.debug("Network %s no-op, deallocate_vip vip %s",
Expand All @@ -43,6 +50,17 @@ def plug_vip(self, load_balancer, vip):
self.networkconfigconfig[(load_balancer.id,
vip.ip_address)] = (load_balancer, vip,
'plug_vip')
amps = []
for amphora in load_balancer.amphorae:
amps.append(data_models.Amphora(
id=amphora.id,
compute_id=amphora.compute_id,
vrrp_ip='198.51.100.1',
ha_ip='198.51.100.1',
vrrp_port_id=uuidutils.generate_uuid(),
ha_port_id=uuidutils.generate_uuid()
))
return amps

def unplug_vip(self, load_balancer, vip):
LOG.debug("Network %s no-op, unplug_vip load_balancer %s, vip %s",
Expand All @@ -58,6 +76,13 @@ def plug_network(self, compute_id, network_id, ip_address=None):
network_id, ip_address)
self.networkconfigconfig[(compute_id, network_id, ip_address)] = (
compute_id, network_id, ip_address, 'plug_network')
return network_models.Interface(
id=uuidutils.generate_uuid(),
compute_id=compute_id,
network_id=network_id,
fixed_ips=[],
port_id=uuidutils.generate_uuid()
)

def unplug_network(self, compute_id, network_id, ip_address=None):
LOG.debug("Network %s no-op, unplug_network compute_id %s, "
Expand All @@ -71,6 +96,7 @@ def get_plugged_networks(self, compute_id):
self.__class__.__name__, compute_id)
self.networkconfigconfig[compute_id] = (
compute_id, 'get_plugged_networks')
return []

def update_vip(self, load_balancer):
LOG.debug("Network %s no-op, update_vip load_balancer %s",
Expand All @@ -81,16 +107,19 @@ def get_network(self, network_id):
LOG.debug("Network %s no-op, get_network network_id %s",
self.__class__.__name__, network_id)
self.networkconfigconfig[network_id] = (network_id, 'get_network')
return network_models.Network(id=uuidutils.generate_uuid())

def get_subnet(self, subnet_id):
LOG.debug("Subnet %s no-op, get_subnet subnet_id %s",
self.__class__.__name__, subnet_id)
self.networkconfigconfig[subnet_id] = (subnet_id, 'get_subnet')
return network_models.Subnet(id=uuidutils.generate_uuid())

def get_port(self, port_id):
LOG.debug("Port %s no-op, get_port port_id %s",
self.__class__.__name__, port_id)
self.networkconfigconfig[port_id] = (port_id, 'get_port')
return network_models.Port(id=uuidutils.generate_uuid())

def failover_preparation(self, amphora):
LOG.debug("failover %s no-op, failover_preparation, amphora id %s",
Expand All @@ -103,38 +132,38 @@ def __init__(self, region=None):
self.driver = NoopManager()

def allocate_vip(self, load_balancer):
self.driver.allocate_vip(load_balancer)
return self.driver.allocate_vip(load_balancer)

def deallocate_vip(self, vip):
self.driver.deallocate_vip(vip)

def plug_vip(self, load_balancer, vip):
self.driver.plug_vip(load_balancer, vip)
return self.driver.plug_vip(load_balancer, vip)

def unplug_vip(self, load_balancer, vip):
self.driver.unplug_vip(load_balancer, vip)

def plug_network(self, amphora_id, network_id, ip_address=None):
self.driver.plug_network(amphora_id, network_id, ip_address)
return self.driver.plug_network(amphora_id, network_id, ip_address)

def unplug_network(self, amphora_id, network_id, ip_address=None):
self.driver.unplug_network(amphora_id, network_id,
ip_address=ip_address)

def get_plugged_networks(self, amphora_id):
self.driver.get_plugged_networks(amphora_id)
return self.driver.get_plugged_networks(amphora_id)

def update_vip(self, load_balancer):
self.driver.update_vip(load_balancer)

def get_network(self, network_id):
self.driver.get_network(network_id)
return self.driver.get_network(network_id)

def get_subnet(self, subnet_id):
self.driver.get_subnet(subnet_id)
return self.driver.get_subnet(subnet_id)

def get_port(self, port_id):
self.driver.get_port(port_id)
return self.driver.get_port(port_id)

def failover_preparation(self, amphora):
self.driver.failover_preparation(amphora)
Expand Up @@ -55,6 +55,7 @@ def setUp(self):
id=FAKE_UUID_1, amphorae=[self.amphora], vip=self.vip,
listeners=[self.listener])
self.network = network_models.Network(id=self.FAKE_UUID_1)
self.port = network_models.Port(id=uuidutils.generate_uuid())
self.amphorae_net_configs = {
self.amphora.id:
network_models.AmphoraNetworkConfig(
Expand Down Expand Up @@ -109,10 +110,10 @@ def test_finalize_amphora(self):
self.amphora.id])

def test_post_network_plug(self):
self.driver.post_network_plug(self.amphora)
self.assertEqual((self.amphora.id, 'post_network_plug'),
self.driver.driver.amphoraconfig[
self.amphora.id])
self.driver.post_network_plug(self.amphora, self.port)
self.assertEqual((self.amphora.id, self.port.id, 'post_network_plug'),
self.driver.driver.amphoraconfig[(
self.amphora.id, self.port.id)])

def test_post_vip_plug(self):
self.driver.post_vip_plug(self.load_balancer,
Expand Down
Expand Up @@ -220,7 +220,7 @@ def test_delete_amphorae_on_load_balancer(self, mock_driver):
delete_amps = compute_tasks.DeleteAmphoraeOnLoadBalancer()
delete_amps.execute(_load_balancer_mock)

mock_driver.delete.assert_called_once_with(compute_id=COMPUTE_ID)
mock_driver.delete.assert_called_once_with(COMPUTE_ID)

@mock.patch('stevedore.driver.DriverManager.driver')
def test_compute_delete(self, mock_driver):
Expand Down

0 comments on commit 0c80a3b

Please sign in to comment.