Property to attribute

Convert several properties into class level attribute in data-drivers
class hierarchy.

It decreases amount of code and makes workflow more obvious.

Change-Id: Iba6ec79ab4266acbcc90133356953c8aee7180fc
This commit is contained in:
Dmitry Bogun 2016-12-26 17:33:26 +02:00 committed by Andrii Ostapenko
parent a70b832447
commit 9dfef0641a
8 changed files with 18 additions and 54 deletions

View File

@ -22,6 +22,7 @@ from oslo_log import log as logging
import six
from bareon.actions import base
from bareon.drivers.data import base as datadrivers
from bareon import errors
from bareon.utils import fs as fu
from bareon.utils import utils
@ -66,6 +67,8 @@ class ConfigDriveAction(base.BaseAction):
pass
def execute(self):
if not isinstance(self.driver, datadrivers.ConfigDriveDataDriverMixin):
return
self.do_configdrive()
def _make_configdrive_image(self, src_files):

View File

@ -23,7 +23,6 @@ from bareon.utils.partition import TiB
from bareon.utils import utils
from bareon.drivers.data.base import BaseDataDriver
from bareon.drivers.data.base import ConfigDriveDataDriverMixin
from bareon.drivers.data.base import GrubBootloaderDataDriverMixin
from bareon.drivers.data.base import MultibootDeploymentMixin
from bareon.drivers.data.base import PartitioningDataDriverMixin
@ -45,9 +44,9 @@ CONF.register_opts(opts)
class GenericDataDriver(BaseDataDriver,
PartitioningDataDriverMixin,
ProvisioningDataDriverMixin,
ConfigDriveDataDriverMixin,
GrubBootloaderDataDriverMixin,
MultibootDeploymentMixin):
partitions_policy = None
def __init__(self, data):
super(GenericDataDriver, self).__init__(data)
@ -60,6 +59,7 @@ class GenericDataDriver(BaseDataDriver,
# get rid of md over all disks for /boot partition.
self._boot_done = False
# FIXME(dbogun): deprecated by new partitioning code
@property
def partition_scheme(self):
if not hasattr(self, '_partition_scheme'):
@ -70,11 +70,6 @@ class GenericDataDriver(BaseDataDriver,
def hw_partition_scheme(self):
raise NotImplementedError
@property
def partitions_policy(self):
"""Returns string"""
raise NotImplementedError
@property
def image_scheme(self):
if not hasattr(self, '_image_scheme'):
@ -99,20 +94,7 @@ class GenericDataDriver(BaseDataDriver,
self._operating_system = self._get_operating_system()
return self._operating_system
@property
def configdrive_scheme(self):
if not hasattr(self, '_configdrive_scheme'):
self._configdrive_scheme = self._get_configdrive_scheme()
return self._configdrive_scheme
@property
def is_configdrive_needed(self):
raise NotImplementedError
def create_configdrive(self):
if self.is_configdrive_needed:
self._create_configdrive()
# FIXME(dbogun): deprecated by new partitioning code
def _get_partition_scheme(self):
raise NotImplementedError
@ -128,9 +110,6 @@ class GenericDataDriver(BaseDataDriver,
def _get_operating_system(self):
raise NotImplementedError
def _get_configdrive_scheme(self):
raise NotImplementedError
def _create_configdrive(self):
raise NotImplementedError
@ -151,11 +130,13 @@ class GenericDataDriver(BaseDataDriver,
md5=md5,
)
# FIXME(dbogun): deprecated by new partitioning code
@property
def _ks_disks(self):
return filter(lambda x: x['type'] == 'disk' and x['size'] > 0,
self._partition_data())
# FIXME(dbogun): deprecated by new partitioning code
@property
def _ks_vgs(self):
return filter(lambda x: x['type'] == 'vg', self._partition_data())

View File

@ -51,6 +51,7 @@ class Ironic(GenericDataDriver):
super(Ironic, self).__init__(data)
self._original_data = data
convert_size(self.data['partitions'])
self.partitions_policy = self.data.get('partitions_policy', 'verify')
@property
def storage_claim(self):
@ -94,23 +95,12 @@ class Ironic(GenericDataDriver):
def is_multiboot(self):
return True if len(self.get_image_ids()) > 1 else False
@property
def is_configdrive_needed(self):
return False
@property
def hw_partition_scheme(self):
if not hasattr(self, '_hw_partition_scheme'):
self._hw_partition_scheme = self._get_hw_partition_schema()
return self._hw_partition_scheme
@property
def partitions_policy(self):
if not hasattr(self, '_partitions_policy'):
self._partitions_policy = self.data.get('partitions_policy',
'verify')
return self._partitions_policy
@property
def root_on_lvm(self):
return self.partition_scheme and self._root_on_lvm

View File

@ -23,6 +23,7 @@ from oslo_config import cfg
from oslo_log import log as logging
import six
from bareon.actions import configdrive
from bareon.actions import partitioning
from bareon.drivers.deploy.base import BaseDeployDriver
from bareon.drivers.deploy import mixins
@ -92,7 +93,7 @@ class GenericDeployDriver(BaseDeployDriver, mixins.MountableMixin):
LOG.debug('--- Partitioning disks END (do_partitioning) ---')
def do_configdrive(self):
self.driver.create_configdrive()
configdrive.ConfigDriveAction(self.driver).execute()
def do_copyimage(self):
raise NotImplementedError
@ -291,8 +292,8 @@ class GenericDeployDriver(BaseDeployDriver, mixins.MountableMixin):
json.dump(result, boot_entries_file)
# FIXME(dbogun): deprecated due to NEWTCORE-360 fix
class PolicyPartitioner(object):
def __init__(self, driver):
self.driver = driver
self.partitioning = partitioning.PartitioningAction(self.driver)

View File

@ -61,19 +61,6 @@ class TestDoProvision(unittest2.TestCase):
mock_bootloader.assert_called_once_with()
class TestDoConfigDrive(unittest2.TestCase):
def __init__(self, *args, **kwargs):
super(TestDoConfigDrive, self).__init__(*args, **kwargs)
self.mock_data_driver = mock.MagicMock()
self.driver = generic.GenericDeployDriver(self.mock_data_driver)
def test_do_configdrive(self):
result = self.driver.do_configdrive()
self.assertIsNone(result)
self.mock_data_driver.create_configdrive.assert_called_once_with()
class TestMountTarget(unittest2.TestCase):
def __init__(self, *args, **kwargs):
super(TestMountTarget, self).__init__(*args, **kwargs)

View File

@ -25,7 +25,7 @@ echo "================== Rebuilding deploy images =================="
source ${BUILD_ENV:-"bareon/tests_functional/image_build/centos_minimal_env.sh"}
BAREON_PATH=$PWD
BAREON_PATH="$PWD"
rm -rf $BUILD_DIR
mkdir $BUILD_DIR
@ -44,8 +44,8 @@ sed -i -e 's%mv \(/usr/lib/locale/locale-archive\)%cp \1%' diskimage-builder/ele
export PATH=$BUILD_DIR/diskimage-builder/bin:$BUILD_DIR/dib-utils/bin:$PATH
export BAREON_SRC=file://$BAREON_PATH
export BAREON_BRANCH=$(cd $BAREON_PATH && git rev-parse --abbrev-ref HEAD) # Use current branch
export BAREON_SRC="file://$BAREON_PATH"
export BAREON_BRANCH="$(cd $BAREON_PATH && git rev-parse --abbrev-ref HEAD)" # Use current branch
export ELEMENTS_PATH="$BUILD_DIR/bareon-image-elements"

View File

@ -223,7 +223,8 @@ PROVISION_SAMPLE_DATA = {
]
},
"mco_connector": "rabbitmq",
"mco_host": "10.20.0.2"
"mco_host": "10.20.0.2",
"mco_identity": 1
},
"name": "node-1",
"hostname": "node-1.domain.tld",

View File

@ -15,6 +15,7 @@
# under the License.
# FIXME(dbogun): unused
class abstractclassmethod(classmethod):
"""A decorator indicating abstract classmethods.