Add first container_config tests
This commit is contained in:
parent
f0332489bb
commit
0290477230
|
@ -0,0 +1,29 @@
|
|||
# Copyright (c) 2015 Canonical Ltd
|
||||
#
|
||||
# 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.
|
||||
|
||||
import ddt
|
||||
|
||||
|
||||
def annotated_data(*args):
|
||||
class List(list):
|
||||
pass
|
||||
|
||||
new_args = []
|
||||
|
||||
for arg in args:
|
||||
new_arg = List(arg)
|
||||
new_arg.__name__ = arg[0]
|
||||
new_args.append(new_arg)
|
||||
|
||||
return lambda func: ddt.data(*new_args)(ddt.unpack(func))
|
|
@ -13,16 +13,65 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import ddt
|
||||
import mock
|
||||
from nova import test
|
||||
from oslo_config import cfg
|
||||
|
||||
from nclxd.nova.virt.lxd import container_config
|
||||
from nclxd import tests
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
class MockInstance(mock.Mock):
|
||||
|
||||
def __init__(self, name='mock_instance', memory_mb=-1, vcpus=0,
|
||||
*args, **kwargs):
|
||||
super(MockInstance, self).__init__(
|
||||
*args, **kwargs)
|
||||
self.name = name
|
||||
self.flavor = mock.Mock(memory_mb=memory_mb, vcpus=vcpus)
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class LXDTestContainerConfig(test.NoDBTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(LXDTestContainerConfig, self).setUp()
|
||||
self.container_config = container_config.LXDContainerConfig()
|
||||
|
||||
def test_init_config(self):
|
||||
self.assertEqual({'config': {}, 'devices': {}},
|
||||
self.container_config._init_container_config())
|
||||
|
||||
@mock.patch.object(CONF, 'lxd', lxd_default_profile='fake_profile')
|
||||
@mock.patch('nclxd.nova.virt.lxd.container_image'
|
||||
'.LXDContainerImage.fetch_image')
|
||||
@mock.patch('nclxd.nova.virt.lxd.container_utils'
|
||||
'.LXDContainerDirectories.get_console_path',
|
||||
return_value='/fake/path')
|
||||
@tests.annotated_data(
|
||||
('no_rescue', {}, 'mock_instance'),
|
||||
('rescue', {'name_label': 'rescued', 'rescue': True}, 'rescued'),
|
||||
)
|
||||
def test_configure_container(self, tag, kwargs, expected, mp, mf, mc):
|
||||
instance = MockInstance()
|
||||
context = {}
|
||||
network_info = []
|
||||
image_meta = {}
|
||||
self.assertEqual(
|
||||
{'config': {'raw.lxc':
|
||||
'lxc.console.logfile=/fake/path\n'},
|
||||
'devices': {},
|
||||
'name': expected,
|
||||
'profiles': ['fake_profile'],
|
||||
'source': {'alias': 'None', 'type': 'image'}},
|
||||
(self.container_config
|
||||
.configure_container(context,
|
||||
instance,
|
||||
network_info,
|
||||
image_meta,
|
||||
**kwargs)))
|
||||
mf.assert_called_once_with(context, instance, image_meta)
|
||||
mp.assert_called_once_with('mock_instance')
|
||||
|
|
|
@ -6,6 +6,7 @@ hacking>=0.9.2,<0.10
|
|||
|
||||
coverage>=3.6
|
||||
discover
|
||||
ddt
|
||||
python-subunit>=0.0.18
|
||||
sphinx>=1.1.2,!=1.2.0,!=1.3b1,<1.3
|
||||
oslosphinx>=2.2.0 # Apache-2.0
|
||||
|
|
Loading…
Reference in New Issue