Add compute noop driver and test case

1. implement methods in noop_driver/driver.py
2. add unit test class in test_compute_noop_driver

Change-Id: Ifc31c7d819ededd7f350cd1d4207ffd48c49a8bb
This commit is contained in:
minwang 2015-04-10 17:06:13 -07:00
parent f7236de450
commit 0a49aa4b31
3 changed files with 160 additions and 0 deletions

View File

@ -0,0 +1,86 @@
# Copyright 2015 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from oslo_log import log as logging
from octavia.compute import compute_base as driver_base
LOG = logging.getLogger(__name__)
class NoopManager(object):
def __init__(self):
super(NoopManager, self).__init__()
self.computeconfig = {}
def get_logger(self):
LOG.debug("Compute %s no-op", self.__class__.__name__)
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):
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",
self.__class__.__name__, name, amphora_flavor, image_id,
key_name, sec_groups, network_ids, config_drive_files,
user_data)
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')
def delete(self, amphora_id):
LOG.debug("Compute %s no-op, amphora_id %s",
self.__class__.__name__, amphora_id)
self.computeconfig[amphora_id] = (amphora_id, 'delete')
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')
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')
class NoopComputeDriver(driver_base.ComputeBase):
def __init__(self, log):
super(NoopComputeDriver, self).__init__()
self.log = log
self.driver = NoopManager()
def get_logger(self):
self.driver.get_logger()
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):
self.driver.build(name, amphora_flavor, image_id, key_name,
sec_groups, network_ids, config_drive_files,
user_data)
def delete(self, amphora_id):
self.driver.delete(amphora_id)
def status(self, amphora_id):
self.driver.status(amphora_id)
def get_amphora(self, amphora_id):
self.driver.get_amphora(amphora_id)

View File

@ -0,0 +1,74 @@
# Copyright 2015 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from oslo_log import log as logging
from oslo_utils import uuidutils
from octavia.compute.drivers.noop_driver import driver as driver
import octavia.tests.unit.base as base
LOG = logging.getLogger(__name__)
class TestNoopComputeDriver(base.TestCase):
FAKE_UUID_1 = uuidutils.generate_uuid()
FAKE_UUID_2 = uuidutils.generate_uuid()
FAKE_UUID_3 = uuidutils.generate_uuid()
def setUp(self):
super(TestNoopComputeDriver, self).setUp()
self.driver = driver.NoopComputeDriver(LOG)
self.name = "amphora_name"
self.amphora_flavor = "m1.tiny"
self.image_id = self.FAKE_UUID_2
self.key_name = "key_name"
self.sec_groups = "default"
self.network_ids = self.FAKE_UUID_3
self.confdrivefiles = "config_driver_files"
self.user_data = "user_data"
self.amphora_id = self.FAKE_UUID_1
def get_logger(self):
self.driver.get_logger()
def build(self):
self.driver.build(self.name, self.amphora_flavor, self.image_id,
self.key_name, self.sec_groups, self.network_ids,
self.confdrivefiles, self.user_data)
self.assertEqual((self.name, self.amphora_flavor, self.image_id,
self.key_name, self.sec_groups, self.network_ids,
self.config_drive_files, self.user_data, 'build'),
self.driver.driver.computeconfig[(self.name,
self.amphora_flavor,
self.image_id,
self.key_name,
self.sec_groups,
self.network_ids,
self.confdrivefiles,
self.user_data)])
def test_delete(self):
self.driver.delete(self.amphora_id)
self.assertEqual((self.amphora_id, 'delete'),
self.driver.driver.computeconfig[
self.amphora_id])
def status(self):
self.driver.status(self.amphora_id)
def get_amphora(self):
self.driver.get_amphora(self.amphora_id)