Fixup imports and unit tests

This commit is contained in:
James Page 2015-08-13 11:54:25 +01:00
parent d470fd1aca
commit 3598cd5db6
3 changed files with 23 additions and 16 deletions

View File

@ -1,10 +1,11 @@
import os
import shutil
import pwd
import subprocess
from base64 import b64decode
from copy import deepcopy
from subprocess import call, check_call, check_output, CalledProcessError
from subprocess import check_call, check_output, CalledProcessError
from charmhelpers.fetch import (
apt_update,
@ -819,11 +820,11 @@ def install_hugepages():
nr_hugepages=hugepages,
mount=False,
)
if call(['mountpoint', mnt_point]):
if subprocess.call(['mountpoint', mnt_point]):
fstab_mount(mnt_point)
rsync(
charm_dir() + '/files/qemu-hugefsdir',
'/etc/init.d/qemu-hugefsdir'
)
check_call('/etc/init.d/qemu-hugefsdir')
check_call(['update-rc.d', 'qemu-hugefsdir', 'defaults'])
subprocess.check_call('/etc/init.d/qemu-hugefsdir')
subprocess.check_call(['update-rc.d', 'qemu-hugefsdir', 'defaults'])

View File

@ -57,6 +57,7 @@ TO_PATCH = [
# socket
'gethostname',
'create_sysctl',
'install_hugepages',
]

View File

@ -30,9 +30,10 @@ TO_PATCH = [
'add_user_to_group',
'MetadataServiceContext',
'lsb_release',
# subprocess
'call',
'check_call',
'charm_dir',
'hugepage_support',
'rsync',
'fstab_mount',
]
OVS_PKGS = [
@ -57,6 +58,7 @@ class NovaComputeUtilsTests(CharmTestCase):
def setUp(self):
super(NovaComputeUtilsTests, self).setUp(utils, TO_PATCH)
self.config.side_effect = self.test_config.get
self.charm_dir.return_value = 'mycharm'
@patch.object(utils, 'enable_nova_metadata')
@patch.object(utils, 'network_manager')
@ -714,14 +716,15 @@ class NovaComputeUtilsTests(CharmTestCase):
@patch('psutil.virtual_memory')
def test_install_hugepages(self, _virt_mem):
@patch('subprocess.check_call')
@patch('subprocess.call')
def test_install_hugepages(self, _call, _check_call, _virt_mem):
class mem(object):
def __init__(self):
self.total = 10000000
self.user_exists.return_value = True
self.test_config.set('hugepages', '10%')
_virt_mem.side_effect = mem
self.call.return_value = 1
_call.return_value = 1
utils.install_hugepages()
self.hugepage_support.assert_called_with(
'nova',
@ -734,12 +737,13 @@ class NovaComputeUtilsTests(CharmTestCase):
call('/etc/init.d/qemu-hugefsdir'),
call(['update-rc.d', 'qemu-hugefsdir', 'defaults']),
]
self.check_call.assert_has_calls(check_call_calls)
_check_call.assert_has_calls(check_call_calls)
self.fstab_mount.assert_called_with('/mnt/huge')
@patch('psutil.virtual_memory')
def test_install_hugepages_explicit_size(self, _virt_mem):
self.user_exists.return_value = True
@patch('subprocess.check_call')
@patch('subprocess.call')
def test_install_hugepages_explicit_size(self, _call, _check_call, _virt_mem):
self.test_config.set('hugepages', '2048')
utils.install_hugepages()
self.hugepage_support.assert_called_with(
@ -751,9 +755,10 @@ class NovaComputeUtilsTests(CharmTestCase):
)
@patch('psutil.virtual_memory')
def test_install_hugepages_already_mounted(self, _virt_mem):
self.user_exists.return_value = True
@patch('subprocess.check_call')
@patch('subprocess.call')
def test_install_hugepages_already_mounted(self, _call, _check_call, _virt_mem):
self.test_config.set('hugepages', '2048')
self.call.return_value = 0
_call.return_value = 0
utils.install_hugepages()
self.assertEqual(self.fstab_mount.call_args_list, [])