Merge "Reduce memory assigned to CentOS servers to 256MB"
This commit is contained in:
commit
c1cdca0ee9
|
@ -14,7 +14,6 @@
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
import json
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
|
@ -41,6 +40,7 @@ def cloud_config(*args, **kwargs):
|
||||||
def combine_cloud_configs(objs):
|
def combine_cloud_configs(objs):
|
||||||
packages = []
|
packages = []
|
||||||
runcmd = []
|
runcmd = []
|
||||||
|
extra_params = {}
|
||||||
for obj in objs:
|
for obj in objs:
|
||||||
if obj:
|
if obj:
|
||||||
if not isinstance(obj, collections.abc.Mapping):
|
if not isinstance(obj, collections.abc.Mapping):
|
||||||
|
@ -54,12 +54,11 @@ def combine_cloud_configs(objs):
|
||||||
if cmdline:
|
if cmdline:
|
||||||
runcmd.append(cmdline)
|
runcmd.append(cmdline)
|
||||||
if obj:
|
if obj:
|
||||||
message = ('Invalid cloud-init parameters:\n' +
|
extra_params.update(obj)
|
||||||
json.dumps(obj, indent=4, sort_keys=True))
|
|
||||||
raise ValueError(message)
|
|
||||||
|
|
||||||
return CloudConfig.create(packages=packages or None,
|
return CloudConfig.create(packages=packages or None,
|
||||||
runcmd=runcmd or None)
|
runcmd=runcmd or None,
|
||||||
|
**extra_params)
|
||||||
|
|
||||||
|
|
||||||
class CloudConfig(dict):
|
class CloudConfig(dict):
|
||||||
|
|
|
@ -39,7 +39,7 @@ class CentosImageFixture(glance.URLGlanceImageFixture):
|
||||||
|
|
||||||
|
|
||||||
class CentosFlavorStackFixture(_nova.FlavorStackFixture):
|
class CentosFlavorStackFixture(_nova.FlavorStackFixture):
|
||||||
ram = 512
|
ram = 256
|
||||||
|
|
||||||
|
|
||||||
class CentosServerStackFixture(_nova.ServerStackFixture):
|
class CentosServerStackFixture(_nova.ServerStackFixture):
|
||||||
|
@ -49,3 +49,6 @@ class CentosServerStackFixture(_nova.ServerStackFixture):
|
||||||
|
|
||||||
#: Flavor used to create a Nova server instance
|
#: Flavor used to create a Nova server instance
|
||||||
flavor_stack = tobiko.required_setup_fixture(CentosFlavorStackFixture)
|
flavor_stack = tobiko.required_setup_fixture(CentosFlavorStackFixture)
|
||||||
|
|
||||||
|
#: Setup SWAP file in bytes
|
||||||
|
swap_maxsize = 1 * 1024 * 1024 * 1024 # 1 GB
|
||||||
|
|
|
@ -263,12 +263,30 @@ class ServerStackFixture(heat.HeatStackFixture):
|
||||||
return nova.get_console_output(server=self.server_id,
|
return nova.get_console_output(server=self.server_id,
|
||||||
length=self.max_console_output_length)
|
length=self.max_console_output_length)
|
||||||
|
|
||||||
cloud_config = nova.cloud_config()
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def user_data(self):
|
def user_data(self):
|
||||||
return nova.user_data(self.cloud_config)
|
return nova.user_data(self.cloud_config)
|
||||||
|
|
||||||
|
#: SWAP file name
|
||||||
|
swap_filename: str = '/swap.img'
|
||||||
|
#: SWAP file size in bytes
|
||||||
|
swap_size: typing.Optional[int] = None
|
||||||
|
#: nax SWAP file size in bytes
|
||||||
|
swap_maxsize: typing.Optional[int] = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def cloud_config(self):
|
||||||
|
cloud_config = nova.cloud_config()
|
||||||
|
# default is to not create any swap files,
|
||||||
|
# because 'swap_file_max_size' is set to None
|
||||||
|
if self.swap_maxsize is not None:
|
||||||
|
cloud_config = nova.cloud_config(
|
||||||
|
cloud_config,
|
||||||
|
swap={'filename': self.swap_filename,
|
||||||
|
'size': self.swap_size or 'auto',
|
||||||
|
'maxsize': self.swap_maxsize})
|
||||||
|
return cloud_config
|
||||||
|
|
||||||
def ensure_server_status(self, status):
|
def ensure_server_status(self, status):
|
||||||
tobiko.setup_fixture(self)
|
tobiko.setup_fixture(self)
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -15,9 +15,12 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
import yaml
|
||||||
|
|
||||||
import tobiko
|
import tobiko
|
||||||
from tobiko.shell import sh
|
from tobiko.shell import sh
|
||||||
from tobiko.openstack import keystone
|
from tobiko.openstack import keystone
|
||||||
|
from tobiko.openstack import nova
|
||||||
from tobiko.openstack import stacks
|
from tobiko.openstack import stacks
|
||||||
from tobiko.tests.functional.openstack.stacks import test_cirros
|
from tobiko.tests.functional.openstack.stacks import test_cirros
|
||||||
|
|
||||||
|
@ -29,9 +32,19 @@ class CentosServerStackTest(test_cirros.CirrosServerStackTest):
|
||||||
#: Stack of resources with a server attached to a floating IP
|
#: Stack of resources with a server attached to a floating IP
|
||||||
stack = tobiko.required_setup_fixture(stacks.CentosServerStackFixture)
|
stack = tobiko.required_setup_fixture(stacks.CentosServerStackFixture)
|
||||||
|
|
||||||
|
def test_user_data(self):
|
||||||
|
user_data = self.stack.user_data
|
||||||
|
self.assertIsInstance(user_data, str)
|
||||||
|
self.assertTrue(user_data.startswith('#cloud-config\n'), user_data)
|
||||||
|
self.assertEqual(self.stack.cloud_config,
|
||||||
|
yaml.safe_load(user_data))
|
||||||
|
|
||||||
def test_platform_python(self):
|
def test_platform_python(self):
|
||||||
python_version = sh.execute(['/usr/libexec/platform-python',
|
python_version = sh.execute(['/usr/libexec/platform-python',
|
||||||
'--version'],
|
'--version'],
|
||||||
ssh_client=self.stack.ssh_client).stdout
|
ssh_client=self.stack.ssh_client).stdout
|
||||||
self.assertTrue(python_version.startswith('Python 3.'),
|
self.assertTrue(python_version.startswith('Python 3.'),
|
||||||
python_version)
|
python_version)
|
||||||
|
|
||||||
|
def test_cloud_init_done(self):
|
||||||
|
nova.wait_for_cloud_init_done(ssh_client=self.stack.ssh_client)
|
||||||
|
|
|
@ -22,6 +22,7 @@ import testtools
|
||||||
|
|
||||||
import tobiko
|
import tobiko
|
||||||
from tobiko.openstack import keystone
|
from tobiko.openstack import keystone
|
||||||
|
from tobiko.openstack import nova
|
||||||
from tobiko.openstack import stacks
|
from tobiko.openstack import stacks
|
||||||
from tobiko.shell import ping
|
from tobiko.shell import ping
|
||||||
from tobiko.shell import sh
|
from tobiko.shell import sh
|
||||||
|
@ -60,6 +61,27 @@ class CirrosServerStackTest(testtools.TestCase):
|
||||||
output = self.stack.console_output
|
output = self.stack.console_output
|
||||||
self.assertTrue(output)
|
self.assertTrue(output)
|
||||||
|
|
||||||
|
def test_swap_file(self):
|
||||||
|
if self.stack.swap_maxsize is None:
|
||||||
|
self.skipTest('Swap maxsize is None')
|
||||||
|
|
||||||
|
cloud_config = self.stack.cloud_config
|
||||||
|
self.assertEqual({'filename': self.stack.swap_filename,
|
||||||
|
'size': self.stack.swap_size or "auto",
|
||||||
|
'maxsize': self.stack.swap_maxsize},
|
||||||
|
cloud_config['swap'])
|
||||||
|
|
||||||
|
nova.wait_for_cloud_init_done(ssh_client=self.stack.ssh_client)
|
||||||
|
# check swap file exists
|
||||||
|
sh.execute(f"ls -lh '{self.stack.swap_filename}'",
|
||||||
|
ssh_client=self.stack.ssh_client)
|
||||||
|
# check swap file is mounted
|
||||||
|
swaps_table = sh.execute("cat /proc/swaps",
|
||||||
|
ssh_client=self.stack.ssh_client).stdout
|
||||||
|
mounted_filenames = [line.split()[0]
|
||||||
|
for line in swaps_table.splitlines()[1:]]
|
||||||
|
self.assertIn(self.stack.swap_filename, mounted_filenames, swaps_table)
|
||||||
|
|
||||||
def test_ipv4_subnet_nameservers(self):
|
def test_ipv4_subnet_nameservers(self):
|
||||||
self._test_subnet_nameservers(
|
self._test_subnet_nameservers(
|
||||||
subnet=self.stack.network_stack.ipv4_subnet_details,
|
subnet=self.stack.network_stack.ipv4_subnet_details,
|
||||||
|
|
|
@ -36,12 +36,6 @@ class TestUserData(testtools.TestCase):
|
||||||
['echo', '2']]},
|
['echo', '2']]},
|
||||||
user_data)
|
user_data)
|
||||||
|
|
||||||
def test_user_data_with_invalid(self):
|
|
||||||
ex = self.assertRaises(ValueError, nova.user_data, wrong='mistake')
|
|
||||||
self.assertEqual(
|
|
||||||
'Invalid cloud-init parameters:\n{\n "wrong": "mistake"\n}',
|
|
||||||
str(ex))
|
|
||||||
|
|
||||||
def assert_equal_cloud_config(self, expected, actual):
|
def assert_equal_cloud_config(self, expected, actual):
|
||||||
self.assertTrue(actual.startswith('#cloud-config'))
|
self.assertTrue(actual.startswith('#cloud-config'))
|
||||||
self.assertEqual(expected, yaml.load(actual))
|
self.assertEqual(expected, yaml.load(actual))
|
||||||
|
@ -62,9 +56,3 @@ class TestCloudConfig(testtools.TestCase):
|
||||||
self.assertEqual({'runcmd': [['echo', '1'],
|
self.assertEqual({'runcmd': [['echo', '1'],
|
||||||
['echo', '2']]},
|
['echo', '2']]},
|
||||||
cloud_config)
|
cloud_config)
|
||||||
|
|
||||||
def test_cloud_config_with_invalid(self):
|
|
||||||
ex = self.assertRaises(ValueError, nova.cloud_config, wrong='mistake')
|
|
||||||
self.assertEqual(
|
|
||||||
'Invalid cloud-init parameters:\n{\n "wrong": "mistake"\n}',
|
|
||||||
str(ex))
|
|
||||||
|
|
Loading…
Reference in New Issue