Changing reconcile to test_only

In order to make the code easier to understand we came to a conclusion
that changing the variable reconcile to test_only makes more sense.

Change-Id: Ia3cca7a1615c690f9e7af6aff0a393ef0fc06e10
This commit is contained in:
Telles Nobrega 2017-05-29 17:04:03 -03:00
parent 8f406bcfb9
commit d1a0ce06e2
5 changed files with 112 additions and 111 deletions

View File

@ -258,9 +258,9 @@ Two variables are always available to scripts run under this framework:
* ``distro``: The distro of the image, in case you want to switch on distro
within your script (rather than by using the os_case validator).
* ``reconcile``: If this value equates to boolean true, then the script should
* ``test_only``: If this value equates to boolean false, then the script should
attempt to change the image or instance if it does not already meet the
specification. If this equates to boolean false, the script should exit with
specification. If this equates to boolean true, the script should exit with
a failure code if the image or instance does not already meet the
specification.
@ -369,16 +369,16 @@ in the OpenStack context.) We will, of course, focus on that framework here.
"""Gets the argument set taken by the plugin's image generator"""
def pack_image(self, hadoop_version, remote,
reconcile=True, image_arguments=None):
test_only=False, image_arguments=None):
"""Packs an image for registration in Glance and use by Sahara"""
def validate_images(self, cluster, reconcile=True, image_arguments=None):
def validate_images(self, cluster, test_only=False, image_arguments=None):
"""Validates the image to be used by a cluster"""
The validate_images method is called after Heat provisioning of your cluster,
but before cluster configuration. If the reconcile keyword of this method is
set to False, the method should only test the instances without modification.
If it is set to True, the method should make any necessary changes (this can
but before cluster configuration. If the test_only keyword of this method is
set to True, the method should only test the instances without modification.
If it is set to False, the method should make any necessary changes (this can
be used to allow clusters to be spun up from clean, OS-only images.) This
method is expected to use an ssh remote to communicate with instances, as
per normal in Sahara.

View File

@ -54,20 +54,20 @@ def transform_exception(from_type, to_type, transform_func=None):
return decorator
def validate_instance(instance, validators, reconcile=True, **kwargs):
def validate_instance(instance, validators, test_only=False, **kwargs):
"""Runs all validators against the specified instance.
:param instance: An instance to validate.
:param validators: A sequence of ImageValidators.
:param reconcile: If false, all validators will only verify that a
desired state is present, and fail if it is not. If true, all
:param test_only: If true, all validators will only verify that a
desired state is present, and fail if it is not. If false, all
validators will attempt to enforce the desired state if possible,
and succeed if this enforcement succeeds.
:raises ImageValidationError: If validation fails.
"""
with instance.remote() as remote:
for validator in validators:
validator.validate(remote, reconcile=reconcile, **kwargs)
validator.validate(remote, test_only=test_only, **kwargs)
class ImageArgument(object):
@ -120,7 +120,7 @@ class ImageArgument(object):
arg.get('required'),
arg.get('choices'))
for name, arg in six.iteritems(spec)}
reserved_names = ['distro', 'reconcile']
reserved_names = ['distro', 'test_only']
for name, arg in six.iteritems(arguments):
if name in reserved_names:
raise p_ex.ImageValidationSpecificationError(
@ -150,12 +150,12 @@ class ImageValidator(object):
"""Validates the image spawned to an instance via a set of rules."""
@abc.abstractmethod
def validate(self, remote, reconcile=True, **kwargs):
def validate(self, remote, test_only=False, **kwargs):
"""Validates the image.
:param remote: A remote socket to the instance.
:param reconcile: If false, all validators will only verify that a
desired state is present, and fail if it is not. If true, all
:param test_only: If true, all validators will only verify that a
desired state is present, and fail if it is not. If false, all
validators will attempt to enforce the desired state if possible,
and succeed if this enforcement succeeds.
:raises ImageValidationError: If validation fails.
@ -168,7 +168,7 @@ class SaharaImageValidatorBase(ImageValidator):
"""Base class for Sahara's native image validation."""
DISTRO_KEY = 'distro'
RECONCILE_KEY = 'reconcile'
TEST_ONLY_KEY = 'test_only'
ORDERED_VALIDATORS_SCHEMA = {
"type": "array",
@ -294,13 +294,13 @@ class SaharaImageValidatorBase(ImageValidator):
def __nonzero__(self):
return False
def try_validate(self, remote, reconcile=True,
def try_validate(self, remote, test_only=False,
image_arguments=None, **kwargs):
"""Attempts to validate, but returns rather than raising on failure.
:param remote: A remote socket to the instance.
:param reconcile: If false, all validators will only verify that a
desired state is present, and fail if it is not. If true, all
:param test_only: If true, all validators will only verify that a
desired state is present, and fail if it is not. If false, all
validators will attempt to enforce the desired state if possible,
and succeed if this enforcement succeeds.
:param image_arguments: A dictionary of image argument values keyed by
@ -309,7 +309,7 @@ class SaharaImageValidatorBase(ImageValidator):
"""
try:
self.validate(
remote, reconcile=reconcile,
remote, test_only=test_only,
image_arguments=image_arguments, **kwargs)
return True
except p_ex.ImageValidationError as exc:
@ -368,7 +368,7 @@ class SaharaImageValidator(SaharaImageValidatorBase):
self.arguments = arguments
@transform_exception(ex.RemoteCommandException, p_ex.ImageValidationError)
def validate(self, remote, reconcile=True,
def validate(self, remote, test_only=False,
image_arguments=None, **kwargs):
"""Attempts to validate the image.
@ -376,8 +376,8 @@ class SaharaImageValidator(SaharaImageValidatorBase):
steps such as distro discovery.
:param remote: A remote socket to the instance.
:param reconcile: If false, all validators will only verify that a
desired state is present, and fail if it is not. If true, all
:param test_only: If true, all validators will only verify that a
desired state is present, and fail if it is not. If false, all
validators will attempt to enforce the desired state if possible,
and succeed if this enforcement succeeds.
:param image_arguments: A dictionary of image argument values keyed by
@ -403,7 +403,7 @@ class SaharaImageValidator(SaharaImageValidatorBase):
else:
argument_values[name] = value
argument_values[self.DISTRO_KEY] = remote.get_os_distrib()
self.validator.validate(remote, reconcile=reconcile,
self.validator.validate(remote, test_only=test_only,
image_arguments=argument_values)
@ -496,17 +496,17 @@ class SaharaPackageValidator(SaharaImageValidatorBase):
self.packages = packages
@transform_exception(ex.RemoteCommandException, p_ex.ImageValidationError)
def validate(self, remote, reconcile=True,
def validate(self, remote, test_only=False,
image_arguments=None, **kwargs):
"""Attempts to validate package installation on the image.
Even if reconcile=True, attempts to verify previous package
Even if test_only=False, attempts to verify previous package
installation offline before using networked tools to validate or
install new packages.
:param remote: A remote socket to the instance.
:param reconcile: If false, all validators will only verify that a
desired state is present, and fail if it is not. If true, all
:param test_only: If true, all validators will only verify that a
desired state is present, and fail if it is not. If false, all
validators will attempt to enforce the desired state if possible,
and succeed if this enforcement succeeds.
:param image_arguments: A dictionary of image argument values keyed by
@ -523,7 +523,7 @@ class SaharaPackageValidator(SaharaImageValidatorBase):
check(self, remote)
except (ex.SubprocessException, ex.RemoteCommandException,
RuntimeError):
if reconcile:
if not test_only:
install(self, remote)
check(self, remote)
else:
@ -560,7 +560,7 @@ class SaharaPackageValidator(SaharaImageValidatorBase):
class SaharaScriptValidator(SaharaImageValidatorBase):
"""A validator that runs a script on the instance."""
_DEFAULT_ENV_VARS = [SaharaImageValidatorBase.RECONCILE_KEY,
_DEFAULT_ENV_VARS = [SaharaImageValidatorBase.TEST_ONLY_KEY,
SaharaImageValidatorBase.DISTRO_KEY]
SPEC_SCHEMA = {
@ -652,25 +652,25 @@ class SaharaScriptValidator(SaharaImageValidatorBase):
self.output_var = output_var
@transform_exception(ex.RemoteCommandException, p_ex.ImageValidationError)
def validate(self, remote, reconcile=True,
def validate(self, remote, test_only=False,
image_arguments=None, **kwargs):
"""Attempts to validate by running a script on the image.
:param remote: A remote socket to the instance.
:param reconcile: If false, all validators will only verify that a
desired state is present, and fail if it is not. If true, all
:param test_only: If true, all validators will only verify that a
desired state is present, and fail if it is not. If false, all
validators will attempt to enforce the desired state if possible,
and succeed if this enforcement succeeds.
:param image_arguments: A dictionary of image argument values keyed by
argument name.
Note that the key SIV_RECONCILE will be set to 1 if the script
should reconcile and 0 otherwise; all scripts should act on this
Note that the key SIV_TEST_ONLY will be set to 1 if the script
should test_only and 0 otherwise; all scripts should act on this
input if possible. The key SIV_DISTRO will also contain the
distro representation, per `lsb_release -is`.
:raises ImageValidationError: If validation fails.
"""
arguments = copy.deepcopy(image_arguments)
arguments[self.RECONCILE_KEY] = 1 if reconcile else 0
arguments[self.TEST_ONLY_KEY] = 1 if test_only else 0
script = "\n".join(["%(env_vars)s",
"%(script)s"])
env_vars = "\n".join("export %s=%s" % (key, value) for (key, value)
@ -712,11 +712,11 @@ class SaharaAggregateValidator(SaharaImageValidatorBase):
class SaharaAnyValidator(SaharaAggregateValidator):
"""A list of validators, only one of which must succeed."""
def _try_all(self, remote, reconcile=True,
def _try_all(self, remote, test_only=False,
image_arguments=None, **kwargs):
results = []
for validator in self.validators:
result = validator.try_validate(remote, reconcile=reconcile,
result = validator.try_validate(remote, test_only=test_only,
image_arguments=image_arguments,
**kwargs)
results.append(result)
@ -724,28 +724,28 @@ class SaharaAnyValidator(SaharaAggregateValidator):
break
return results
def validate(self, remote, reconcile=True,
def validate(self, remote, test_only=False,
image_arguments=None, **kwargs):
"""Attempts to validate any of the contained validators.
Note that if reconcile=True, this validator will first run all
contained validators using reconcile=False, and succeed immediately
Note that if test_only=False, this validator will first run all
contained validators using test_only=True, and succeed immediately
should any pass validation. If all fail, it will only then run them
using reconcile=True, and again succeed immediately should any pass.
using test_only=False, and again succeed immediately should any pass.
:param remote: A remote socket to the instance.
:param reconcile: If false, all validators will only verify that a
desired state is present, and fail if it is not. If true, all
:param test_only: If true, all validators will only verify that a
desired state is present, and fail if it is not. If false, all
validators will attempt to enforce the desired state if possible,
and succeed if this enforcement succeeds.
:param image_arguments: A dictionary of image argument values keyed by
argument name.
:raises ImageValidationError: If validation fails.
"""
results = self._try_all(remote, reconcile=False,
results = self._try_all(remote, test_only=True,
image_arguments=image_arguments)
if reconcile and not any(results):
results = self._try_all(remote, reconcile=True,
if not test_only and not any(results):
results = self._try_all(remote, test_only=False,
image_arguments=image_arguments)
if not any(results):
raise p_ex.AllValidationsFailedError(result.exception for result
@ -755,12 +755,13 @@ class SaharaAnyValidator(SaharaAggregateValidator):
class SaharaAllValidator(SaharaAggregateValidator):
"""A list of validators, all of which must succeed."""
def validate(self, remote, reconcile=True, image_arguments=None, **kwargs):
def validate(self, remote, test_only=False, image_arguments=None,
**kwargs):
"""Attempts to validate all of the contained validators.
:param remote: A remote socket to the instance.
:param reconcile: If false, all validators will only verify that a
desired state is present, and fail if it is not. If true, all
:param test_only: If true, all validators will only verify that a
desired state is present, and fail if it is not. If false, all
validators will attempt to enforce the desired state if possible,
and succeed if this enforcement succeeds.
:param image_arguments: A dictionary of image argument values keyed by
@ -768,7 +769,7 @@ class SaharaAllValidator(SaharaAggregateValidator):
:raises ImageValidationError: If validation fails.
"""
for validator in self.validators:
validator.validate(remote, reconcile=reconcile,
validator.validate(remote, test_only=test_only,
image_arguments=image_arguments)
@ -818,7 +819,7 @@ class SaharaOSCaseValidator(SaharaImageValidatorBase):
"""
self.distros = distros
def validate(self, remote, reconcile=True,
def validate(self, remote, test_only=False,
image_arguments=None, **kwargs):
"""Attempts to validate depending on distro.
@ -828,8 +829,8 @@ class SaharaOSCaseValidator(SaharaImageValidatorBase):
If no keys match, no validators are run, and validation proceeds.
:param remote: A remote socket to the instance.
:param reconcile: If false, all validators will only verify that a
desired state is present, and fail if it is not. If true, all
:param test_only: If true, all validators will only verify that a
desired state is present, and fail if it is not. If false, all
validators will attempt to enforce the desired state if possible,
and succeed if this enforcement succeeds.
:param image_arguments: A dictionary of image argument values keyed by
@ -842,7 +843,7 @@ class SaharaOSCaseValidator(SaharaImageValidatorBase):
for distro, validator in self.distros:
if distro in matches:
validator.validate(
remote, reconcile=reconcile,
remote, test_only=test_only,
image_arguments=image_arguments)
break
@ -901,13 +902,13 @@ class SaharaArgumentCaseValidator(SaharaImageValidatorBase):
self.argument_name = argument_name
self.cases = cases
def validate(self, remote, reconcile=True,
def validate(self, remote, test_only=False,
image_arguments=None, **kwargs):
"""Attempts to validate depending on argument value.
:param remote: A remote socket to the instance.
:param reconcile: If false, all validators will only verify that a
desired state is present, and fail if it is not. If true, all
:param test_only: If true, all validators will only verify that a
desired state is present, and fail if it is not. If false, all
validators will attempt to enforce the desired state if possible,
and succeed if this enforcement succeeds.
:param image_arguments: A dictionary of image argument values keyed by
@ -921,7 +922,7 @@ class SaharaArgumentCaseValidator(SaharaImageValidatorBase):
value = image_arguments[arg]
if value in self.cases:
self.cases[value].validate(
remote, reconcile=reconcile,
remote, test_only=test_only,
image_arguments=image_arguments)
@ -972,13 +973,13 @@ class SaharaArgumentSetterValidator(SaharaImageValidatorBase):
self.argument_name = argument_name
self.value = value
def validate(self, remote, reconcile=True,
def validate(self, remote, test_only=False,
image_arguments=None, **kwargs):
"""Attempts to validate depending on argument value.
:param remote: A remote socket to the instance.
:param reconcile: If false, all validators will only verify that a
desired state is present, and fail if it is not. If true, all
:param test_only: If true, all validators will only verify that a
desired state is present, and fail if it is not. If false, all
validators will attempt to enforce the desired state if possible,
and succeed if this enforcement succeeds.
:param image_arguments: A dictionary of image argument values keyed by

View File

@ -135,24 +135,24 @@ class ProvisioningPluginBase(plugins_base.PluginInterface):
@plugins_base.optional
def pack_image(self, hadoop_version, remote,
reconcile=True, image_arguments=None):
test_only=False, image_arguments=None):
"""Packs an image for registration in Glance and use by Sahara
:param remote: A remote (usually of type
sahara.cli.image_pack.api.ImageRemote) that serves as a handle to
the image to modify. Note that this image will be modified
in-place, not copied.
:param reconcile: If set to False, this method will only test to
:param test_only: If set to True, this method will only test to
ensure that the image already meets the plugin's requirements.
This can be used to test images without modification. If set to
True per the default, this method will modify the image if any
False per the default, this method will modify the image if any
requirements are not met.
:param image_arguments: A dict of image argument name to argument
value.
:raises: sahara.plugins.exceptions.ImageValidationError: If the method
fails to modify the image to specification (if reconcile is True),
fails to modify the image to specification (if test_only is False),
or if the method finds that the image does not meet the
specification (if reconcile is False).
specification (if test_only is True).
:raises: sahara.plugins.exceptions.ImageValidationSpecificationError:
If the specification for image generation or validation is itself
in error and cannot be executed without repair.
@ -160,22 +160,22 @@ class ProvisioningPluginBase(plugins_base.PluginInterface):
pass
@plugins_base.optional
def validate_images(self, cluster, reconcile=True, image_arguments=None):
def validate_images(self, cluster, test_only=False, image_arguments=None):
"""Validates the image to be used by a cluster.
:param cluster: The object handle to a cluster which has active
instances ready to generate remote handles.
:param reconcile: If set to False, this method will only test to
:param test_only: If set to True, this method will only test to
ensure that the image already meets the plugin's requirements.
This can be used to test images without modification. If set to
True per the default, this method will modify the image if any
False per the default, this method will modify the image if any
requirements are not met.
:param image_arguments: A dict of image argument name to argument
value.
:raises: sahara.plugins.exceptions.ImageValidationError: If the method
fails to modify the image to specification (if reconcile is True),
fails to modify the image to specification (if test_only is False),
or if the method finds that the image does not meet the
specification (if reconcile is False).
specification (if test_only is True).
:raises: sahara.plugins.exceptions.ImageValidationSpecificationError:
If the specification for image generation or validation is itself
in error and cannot be executed without repair.

View File

@ -289,7 +289,7 @@ def _provision_cluster(cluster_id):
cluster, c_u.CLUSTER_STATUS_CONFIGURING)
context.set_step_type(_("Plugin: configure cluster"))
if hasattr(plugin, 'validate_images'):
plugin.validate_images(cluster, reconcile=True)
plugin.validate_images(cluster, test_only=False)
shares.mount_shares(cluster)
plugin.configure_cluster(cluster)

View File

@ -47,14 +47,14 @@ class TestImages(b.SaharaTestCase):
validator = cls.from_spec('test_images.py', {}, resource_roots)
self.assertIsInstance(validator, cls)
self.assertEqual(validator.env_vars, ['reconcile', 'distro'])
self.assertEqual(validator.env_vars, ['test_only', 'distro'])
validator = cls.from_spec(
{'test_images.py': {'env_vars': ['extra-file', 'user']}},
{}, resource_roots)
self.assertIsInstance(validator, cls)
self.assertEqual(validator.env_vars,
['reconcile', 'distro',
['test_only', 'distro',
'extra-file', 'user'])
def test_all_spec(self):
@ -181,7 +181,7 @@ class TestImages(b.SaharaTestCase):
packages = [cls.Package("java", "8")]
validator = images.SaharaPackageValidator(packages)
remote = mock.Mock()
validator.validate(remote, reconcile=False,
validator.validate(remote, test_only=True,
image_arguments=image_arguments)
remote.execute_command.assert_called_with(
"rpm -q java-8", run_as_root=True)
@ -193,7 +193,7 @@ class TestImages(b.SaharaTestCase):
remote.execute_command.side_effect = (
ex.RemoteCommandException("So bad!"))
try:
validator.validate(remote, reconcile=False,
validator.validate(remote, test_only=True,
image_arguments=image_arguments)
except p_ex.ImageValidationError as e:
self.assertIn("So bad!", e.message)
@ -212,7 +212,7 @@ class TestImages(b.SaharaTestCase):
remote.execute_command.side_effect = side_effect
try:
validator.validate(remote, reconcile=True,
validator.validate(remote, test_only=False,
image_arguments=image_arguments)
except p_ex.ImageValidationError as e:
self.assertIn("So bad!", e.message)
@ -229,7 +229,7 @@ class TestImages(b.SaharaTestCase):
packages = [cls.Package("java", "8")]
validator = images.SaharaPackageValidator(packages)
remote = mock.Mock()
validator.validate(remote, reconcile=False,
validator.validate(remote, test_only=True,
image_arguments=image_arguments)
remote.execute_command.assert_called_with(
"dpkg -s java-8", run_as_root=True)
@ -241,7 +241,7 @@ class TestImages(b.SaharaTestCase):
remote.execute_command.side_effect = (
ex.RemoteCommandException("So bad!"))
try:
validator.validate(remote, reconcile=False,
validator.validate(remote, test_only=True,
image_arguments=image_arguments)
except p_ex.ImageValidationError as e:
self.assertIn("So bad!", e.message)
@ -256,7 +256,7 @@ class TestImages(b.SaharaTestCase):
remote.execute_command.side_effect = (
ex.RemoteCommandException("So bad!"))
try:
validator.validate(remote, reconcile=True,
validator.validate(remote, test_only=False,
image_arguments=image_arguments)
except p_ex.ImageValidationError as e:
self.assertIn("So bad!", e.message)
@ -279,7 +279,7 @@ class TestImages(b.SaharaTestCase):
execute_command=mock.Mock(
return_value=(0, 'fedora')))
validator.validate(remote, reconcile=True,
validator.validate(remote, test_only=False,
image_arguments=image_arguments)
call = [mock.call(map_rep + cmd, run_as_root=True)]
remote.execute_command.assert_has_calls(call)
@ -293,31 +293,31 @@ class TestImages(b.SaharaTestCase):
def __init__(self, mock_validate):
self.mock_validate = mock_validate
def validate(self, remote, reconcile=True, **kwargs):
self.mock_validate(remote, reconcile=reconcile, **kwargs)
def validate(self, remote, test_only=False, **kwargs):
self.mock_validate(remote, test_only=test_only, **kwargs)
# One success short circuits validation
always_tells_the_truth = FakeValidator(mock.Mock())
validator = cls([always_tells_the_truth, always_tells_the_truth])
validator.validate(None, reconcile=True)
validator.validate(None, test_only=False)
self.assertEqual(always_tells_the_truth.mock_validate.call_count, 1)
# All failures fails, and calls with reconcile=False on all first
# All failures fails, and calls with test_only=True on all first
always_lies = FakeValidator(
mock.Mock(side_effect=p_ex.ImageValidationError("Oh no!")))
validator = cls([always_lies, always_lies])
try:
validator.validate(None, reconcile=True)
validator.validate(None, test_only=False)
except p_ex.ImageValidationError:
pass
self.assertEqual(always_lies.mock_validate.call_count, 4)
# But it fails after a first pass if reconcile=False.
# But it fails after a first pass if test_only=True.
always_lies = FakeValidator(
mock.Mock(side_effect=p_ex.ImageValidationError("Oh no!")))
validator = cls([always_lies, always_lies])
try:
validator.validate(None, reconcile=False)
validator.validate(None, test_only=True)
except p_ex.ImageValidationError:
pass
self.assertEqual(always_lies.mock_validate.call_count, 2)
@ -327,7 +327,7 @@ class TestImages(b.SaharaTestCase):
always_lies = FakeValidator(
mock.Mock(side_effect=p_ex.ImageValidationError("Oh no!")))
validator = cls([always_lies, always_tells_the_truth])
validator.validate(None, reconcile=True)
validator.validate(None, test_only=False)
self.assertEqual(always_lies.mock_validate.call_count, 1)
self.assertEqual(always_tells_the_truth.mock_validate.call_count, 1)
@ -337,10 +337,10 @@ class TestImages(b.SaharaTestCase):
# All pass
always_tells_the_truth = mock.Mock()
validator = cls([always_tells_the_truth, always_tells_the_truth])
validator.validate(None, reconcile=True)
validator.validate(None, test_only=False)
self.assertEqual(always_tells_the_truth.validate.call_count, 2)
always_tells_the_truth.validate.assert_called_with(
None, reconcile=True, image_arguments=None)
None, test_only=False, image_arguments=None)
# Second fails
always_tells_the_truth = mock.Mock()
@ -348,15 +348,15 @@ class TestImages(b.SaharaTestCase):
side_effect=p_ex.ImageValidationError("Boom!")))
validator = cls([always_tells_the_truth, always_lies])
try:
validator.validate(None, reconcile=False)
validator.validate(None, test_only=True)
except p_ex.ImageValidationError:
pass
self.assertEqual(always_tells_the_truth.validate.call_count, 1)
self.assertEqual(always_lies.validate.call_count, 1)
always_tells_the_truth.validate.assert_called_with(
None, reconcile=False, image_arguments=None)
None, test_only=True, image_arguments=None)
always_lies.validate.assert_called_with(
None, reconcile=False, image_arguments=None)
None, test_only=True, image_arguments=None)
# First fails
always_tells_the_truth = mock.Mock()
@ -364,12 +364,12 @@ class TestImages(b.SaharaTestCase):
side_effect=p_ex.ImageValidationError("Boom!")))
validator = cls([always_lies, always_tells_the_truth])
try:
validator.validate(None, reconcile=False, image_arguments={})
validator.validate(None, test_only=True, image_arguments={})
except p_ex.ImageValidationError:
pass
self.assertEqual(always_lies.validate.call_count, 1)
always_lies.validate.assert_called_with(
None, reconcile=False, image_arguments={})
None, test_only=True, image_arguments={})
self.assertEqual(always_tells_the_truth.validate.call_count, 0)
def test_os_case_validator(self):
@ -382,12 +382,12 @@ class TestImages(b.SaharaTestCase):
distros = [centos, redhat]
image_arguments = {images.SaharaImageValidator.DISTRO_KEY: "centos"}
validator = cls(distros)
validator.validate(None, reconcile=True,
validator.validate(None, test_only=False,
image_arguments=image_arguments)
self.assertEqual(centos.validator.validate.call_count, 1)
self.assertEqual(redhat.validator.validate.call_count, 0)
centos.validator.validate.assert_called_with(
None, reconcile=True, image_arguments=image_arguments)
None, test_only=False, image_arguments=image_arguments)
# Families match
centos = Distro("centos", mock.Mock())
@ -395,12 +395,12 @@ class TestImages(b.SaharaTestCase):
distros = [centos, redhat]
image_arguments = {images.SaharaImageValidator.DISTRO_KEY: "fedora"}
validator = cls(distros)
validator.validate(None, reconcile=True,
validator.validate(None, test_only=False,
image_arguments=image_arguments)
self.assertEqual(centos.validator.validate.call_count, 0)
self.assertEqual(redhat.validator.validate.call_count, 1)
redhat.validator.validate.assert_called_with(
None, reconcile=True, image_arguments=image_arguments)
None, test_only=False, image_arguments=image_arguments)
# Non-matches do nothing
centos = Distro("centos", mock.Mock())
@ -408,7 +408,7 @@ class TestImages(b.SaharaTestCase):
distros = [centos, redhat]
image_arguments = {images.SaharaImageValidator.DISTRO_KEY: "ubuntu"}
validator = cls(distros)
validator.validate(None, reconcile=True,
validator.validate(None, test_only=False,
image_arguments=image_arguments)
self.assertEqual(centos.validator.validate.call_count, 0)
self.assertEqual(redhat.validator.validate.call_count, 0)
@ -423,12 +423,12 @@ class TestImages(b.SaharaTestCase):
cases = {"value": match,
"another_value": nomatch}
validator = cls("argument", cases)
validator.validate(None, reconcile=True,
validator.validate(None, test_only=False,
image_arguments=image_arguments)
self.assertEqual(match.validate.call_count, 1)
self.assertEqual(nomatch.validate.call_count, 0)
match.validate.assert_called_with(
None, reconcile=True, image_arguments=image_arguments)
None, test_only=False, image_arguments=image_arguments)
# Non-matches do nothing
image_arguments = {"argument": "value"}
@ -436,7 +436,7 @@ class TestImages(b.SaharaTestCase):
cases = {"some_value": nomatch,
"another_value": nomatch}
validator = cls("argument", cases)
validator.validate(None, reconcile=True,
validator.validate(None, test_only=False,
image_arguments=image_arguments)
self.assertEqual(nomatch.validate.call_count, 0)
@ -446,14 +446,14 @@ class TestImages(b.SaharaTestCase):
# Old variable is overwritten
image_arguments = {"argument": "value"}
validator = cls("argument", "new_value")
validator.validate(None, reconcile=True,
validator.validate(None, test_only=False,
image_arguments=image_arguments)
self.assertEqual(image_arguments["argument"], "new_value")
# New variable is set
image_arguments = {"argument": "value"}
validator = cls("another_argument", "value")
validator.validate(None, reconcile=True,
validator.validate(None, test_only=False,
image_arguments=image_arguments)
self.assertEqual(image_arguments,
{"argument": "value", "another_argument": "value"})
@ -465,11 +465,11 @@ class TestImages(b.SaharaTestCase):
remote = mock.Mock(get_os_distrib=mock.Mock(
return_value="centos"))
validator = cls(sub_validator, {})
validator.validate(remote, reconcile=True, image_arguments={})
validator.validate(remote, test_only=False, image_arguments={})
expected_map = {images.SaharaImageValidatorBase.DISTRO_KEY: "centos"}
sub_validator.validate.assert_called_with(
remote, reconcile=True, image_arguments=expected_map)
remote, test_only=False, image_arguments=expected_map)
expected_map = {images.SaharaImageValidatorBase.DISTRO_KEY: "centos"}
validator.validate(remote, reconcile=False, image_arguments={})
validator.validate(remote, test_only=True, image_arguments={})
sub_validator.validate.assert_called_with(
remote, reconcile=False, image_arguments=expected_map)
remote, test_only=True, image_arguments=expected_map)