Merge "Changing reconcile to test_only"
This commit is contained in:
commit
83c7506076
@ -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
|
* ``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).
|
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
|
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
|
a failure code if the image or instance does not already meet the
|
||||||
specification.
|
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"""
|
"""Gets the argument set taken by the plugin's image generator"""
|
||||||
|
|
||||||
def pack_image(self, hadoop_version, remote,
|
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"""
|
"""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"""
|
"""Validates the image to be used by a cluster"""
|
||||||
|
|
||||||
The validate_images method is called after Heat provisioning of your 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
|
but before cluster configuration. If the test_only keyword of this method is
|
||||||
set to False, the method should only test the instances without modification.
|
set to True, the method should only test the instances without modification.
|
||||||
If it is set to True, the method should make any necessary changes (this can
|
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
|
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
|
method is expected to use an ssh remote to communicate with instances, as
|
||||||
per normal in Sahara.
|
per normal in Sahara.
|
||||||
|
@ -54,20 +54,20 @@ def transform_exception(from_type, to_type, transform_func=None):
|
|||||||
return decorator
|
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.
|
"""Runs all validators against the specified instance.
|
||||||
|
|
||||||
:param instance: An instance to validate.
|
:param instance: An instance to validate.
|
||||||
:param validators: A sequence of ImageValidators.
|
:param validators: A sequence of ImageValidators.
|
||||||
:param reconcile: If false, all validators will only verify that a
|
:param test_only: If true, all validators will only verify that a
|
||||||
desired state is present, and fail if it is not. If true, all
|
desired state is present, and fail if it is not. If false, all
|
||||||
validators will attempt to enforce the desired state if possible,
|
validators will attempt to enforce the desired state if possible,
|
||||||
and succeed if this enforcement succeeds.
|
and succeed if this enforcement succeeds.
|
||||||
:raises ImageValidationError: If validation fails.
|
:raises ImageValidationError: If validation fails.
|
||||||
"""
|
"""
|
||||||
with instance.remote() as remote:
|
with instance.remote() as remote:
|
||||||
for validator in validators:
|
for validator in validators:
|
||||||
validator.validate(remote, reconcile=reconcile, **kwargs)
|
validator.validate(remote, test_only=test_only, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class ImageArgument(object):
|
class ImageArgument(object):
|
||||||
@ -120,7 +120,7 @@ class ImageArgument(object):
|
|||||||
arg.get('required'),
|
arg.get('required'),
|
||||||
arg.get('choices'))
|
arg.get('choices'))
|
||||||
for name, arg in six.iteritems(spec)}
|
for name, arg in six.iteritems(spec)}
|
||||||
reserved_names = ['distro', 'reconcile']
|
reserved_names = ['distro', 'test_only']
|
||||||
for name, arg in six.iteritems(arguments):
|
for name, arg in six.iteritems(arguments):
|
||||||
if name in reserved_names:
|
if name in reserved_names:
|
||||||
raise p_ex.ImageValidationSpecificationError(
|
raise p_ex.ImageValidationSpecificationError(
|
||||||
@ -150,12 +150,12 @@ class ImageValidator(object):
|
|||||||
"""Validates the image spawned to an instance via a set of rules."""
|
"""Validates the image spawned to an instance via a set of rules."""
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def validate(self, remote, reconcile=True, **kwargs):
|
def validate(self, remote, test_only=False, **kwargs):
|
||||||
"""Validates the image.
|
"""Validates the image.
|
||||||
|
|
||||||
:param remote: A remote socket to the instance.
|
:param remote: A remote socket to the instance.
|
||||||
:param reconcile: If false, all validators will only verify that a
|
:param test_only: If true, all validators will only verify that a
|
||||||
desired state is present, and fail if it is not. If true, all
|
desired state is present, and fail if it is not. If false, all
|
||||||
validators will attempt to enforce the desired state if possible,
|
validators will attempt to enforce the desired state if possible,
|
||||||
and succeed if this enforcement succeeds.
|
and succeed if this enforcement succeeds.
|
||||||
:raises ImageValidationError: If validation fails.
|
:raises ImageValidationError: If validation fails.
|
||||||
@ -168,7 +168,7 @@ class SaharaImageValidatorBase(ImageValidator):
|
|||||||
"""Base class for Sahara's native image validation."""
|
"""Base class for Sahara's native image validation."""
|
||||||
|
|
||||||
DISTRO_KEY = 'distro'
|
DISTRO_KEY = 'distro'
|
||||||
RECONCILE_KEY = 'reconcile'
|
TEST_ONLY_KEY = 'test_only'
|
||||||
|
|
||||||
ORDERED_VALIDATORS_SCHEMA = {
|
ORDERED_VALIDATORS_SCHEMA = {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
@ -294,13 +294,13 @@ class SaharaImageValidatorBase(ImageValidator):
|
|||||||
def __nonzero__(self):
|
def __nonzero__(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def try_validate(self, remote, reconcile=True,
|
def try_validate(self, remote, test_only=False,
|
||||||
image_arguments=None, **kwargs):
|
image_arguments=None, **kwargs):
|
||||||
"""Attempts to validate, but returns rather than raising on failure.
|
"""Attempts to validate, but returns rather than raising on failure.
|
||||||
|
|
||||||
:param remote: A remote socket to the instance.
|
:param remote: A remote socket to the instance.
|
||||||
:param reconcile: If false, all validators will only verify that a
|
:param test_only: If true, all validators will only verify that a
|
||||||
desired state is present, and fail if it is not. If true, all
|
desired state is present, and fail if it is not. If false, all
|
||||||
validators will attempt to enforce the desired state if possible,
|
validators will attempt to enforce the desired state if possible,
|
||||||
and succeed if this enforcement succeeds.
|
and succeed if this enforcement succeeds.
|
||||||
:param image_arguments: A dictionary of image argument values keyed by
|
:param image_arguments: A dictionary of image argument values keyed by
|
||||||
@ -309,7 +309,7 @@ class SaharaImageValidatorBase(ImageValidator):
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
self.validate(
|
self.validate(
|
||||||
remote, reconcile=reconcile,
|
remote, test_only=test_only,
|
||||||
image_arguments=image_arguments, **kwargs)
|
image_arguments=image_arguments, **kwargs)
|
||||||
return True
|
return True
|
||||||
except p_ex.ImageValidationError as exc:
|
except p_ex.ImageValidationError as exc:
|
||||||
@ -368,7 +368,7 @@ class SaharaImageValidator(SaharaImageValidatorBase):
|
|||||||
self.arguments = arguments
|
self.arguments = arguments
|
||||||
|
|
||||||
@transform_exception(ex.RemoteCommandException, p_ex.ImageValidationError)
|
@transform_exception(ex.RemoteCommandException, p_ex.ImageValidationError)
|
||||||
def validate(self, remote, reconcile=True,
|
def validate(self, remote, test_only=False,
|
||||||
image_arguments=None, **kwargs):
|
image_arguments=None, **kwargs):
|
||||||
"""Attempts to validate the image.
|
"""Attempts to validate the image.
|
||||||
|
|
||||||
@ -376,8 +376,8 @@ class SaharaImageValidator(SaharaImageValidatorBase):
|
|||||||
steps such as distro discovery.
|
steps such as distro discovery.
|
||||||
|
|
||||||
:param remote: A remote socket to the instance.
|
:param remote: A remote socket to the instance.
|
||||||
:param reconcile: If false, all validators will only verify that a
|
:param test_only: If true, all validators will only verify that a
|
||||||
desired state is present, and fail if it is not. If true, all
|
desired state is present, and fail if it is not. If false, all
|
||||||
validators will attempt to enforce the desired state if possible,
|
validators will attempt to enforce the desired state if possible,
|
||||||
and succeed if this enforcement succeeds.
|
and succeed if this enforcement succeeds.
|
||||||
:param image_arguments: A dictionary of image argument values keyed by
|
:param image_arguments: A dictionary of image argument values keyed by
|
||||||
@ -403,7 +403,7 @@ class SaharaImageValidator(SaharaImageValidatorBase):
|
|||||||
else:
|
else:
|
||||||
argument_values[name] = value
|
argument_values[name] = value
|
||||||
argument_values[self.DISTRO_KEY] = remote.get_os_distrib()
|
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)
|
image_arguments=argument_values)
|
||||||
|
|
||||||
|
|
||||||
@ -496,17 +496,17 @@ class SaharaPackageValidator(SaharaImageValidatorBase):
|
|||||||
self.packages = packages
|
self.packages = packages
|
||||||
|
|
||||||
@transform_exception(ex.RemoteCommandException, p_ex.ImageValidationError)
|
@transform_exception(ex.RemoteCommandException, p_ex.ImageValidationError)
|
||||||
def validate(self, remote, reconcile=True,
|
def validate(self, remote, test_only=False,
|
||||||
image_arguments=None, **kwargs):
|
image_arguments=None, **kwargs):
|
||||||
"""Attempts to validate package installation on the image.
|
"""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
|
installation offline before using networked tools to validate or
|
||||||
install new packages.
|
install new packages.
|
||||||
|
|
||||||
:param remote: A remote socket to the instance.
|
:param remote: A remote socket to the instance.
|
||||||
:param reconcile: If false, all validators will only verify that a
|
:param test_only: If true, all validators will only verify that a
|
||||||
desired state is present, and fail if it is not. If true, all
|
desired state is present, and fail if it is not. If false, all
|
||||||
validators will attempt to enforce the desired state if possible,
|
validators will attempt to enforce the desired state if possible,
|
||||||
and succeed if this enforcement succeeds.
|
and succeed if this enforcement succeeds.
|
||||||
:param image_arguments: A dictionary of image argument values keyed by
|
:param image_arguments: A dictionary of image argument values keyed by
|
||||||
@ -523,7 +523,7 @@ class SaharaPackageValidator(SaharaImageValidatorBase):
|
|||||||
check(self, remote)
|
check(self, remote)
|
||||||
except (ex.SubprocessException, ex.RemoteCommandException,
|
except (ex.SubprocessException, ex.RemoteCommandException,
|
||||||
RuntimeError):
|
RuntimeError):
|
||||||
if reconcile:
|
if not test_only:
|
||||||
install(self, remote)
|
install(self, remote)
|
||||||
check(self, remote)
|
check(self, remote)
|
||||||
else:
|
else:
|
||||||
@ -560,7 +560,7 @@ class SaharaPackageValidator(SaharaImageValidatorBase):
|
|||||||
class SaharaScriptValidator(SaharaImageValidatorBase):
|
class SaharaScriptValidator(SaharaImageValidatorBase):
|
||||||
"""A validator that runs a script on the instance."""
|
"""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]
|
SaharaImageValidatorBase.DISTRO_KEY]
|
||||||
|
|
||||||
SPEC_SCHEMA = {
|
SPEC_SCHEMA = {
|
||||||
@ -652,25 +652,25 @@ class SaharaScriptValidator(SaharaImageValidatorBase):
|
|||||||
self.output_var = output_var
|
self.output_var = output_var
|
||||||
|
|
||||||
@transform_exception(ex.RemoteCommandException, p_ex.ImageValidationError)
|
@transform_exception(ex.RemoteCommandException, p_ex.ImageValidationError)
|
||||||
def validate(self, remote, reconcile=True,
|
def validate(self, remote, test_only=False,
|
||||||
image_arguments=None, **kwargs):
|
image_arguments=None, **kwargs):
|
||||||
"""Attempts to validate by running a script on the image.
|
"""Attempts to validate by running a script on the image.
|
||||||
|
|
||||||
:param remote: A remote socket to the instance.
|
:param remote: A remote socket to the instance.
|
||||||
:param reconcile: If false, all validators will only verify that a
|
:param test_only: If true, all validators will only verify that a
|
||||||
desired state is present, and fail if it is not. If true, all
|
desired state is present, and fail if it is not. If false, all
|
||||||
validators will attempt to enforce the desired state if possible,
|
validators will attempt to enforce the desired state if possible,
|
||||||
and succeed if this enforcement succeeds.
|
and succeed if this enforcement succeeds.
|
||||||
:param image_arguments: A dictionary of image argument values keyed by
|
:param image_arguments: A dictionary of image argument values keyed by
|
||||||
argument name.
|
argument name.
|
||||||
Note that the key SIV_RECONCILE will be set to 1 if the script
|
Note that the key SIV_TEST_ONLY will be set to 1 if the script
|
||||||
should reconcile and 0 otherwise; all scripts should act on this
|
should test_only and 0 otherwise; all scripts should act on this
|
||||||
input if possible. The key SIV_DISTRO will also contain the
|
input if possible. The key SIV_DISTRO will also contain the
|
||||||
distro representation, per `lsb_release -is`.
|
distro representation, per `lsb_release -is`.
|
||||||
:raises ImageValidationError: If validation fails.
|
:raises ImageValidationError: If validation fails.
|
||||||
"""
|
"""
|
||||||
arguments = copy.deepcopy(image_arguments)
|
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 = "\n".join(["%(env_vars)s",
|
||||||
"%(script)s"])
|
"%(script)s"])
|
||||||
env_vars = "\n".join("export %s=%s" % (key, value) for (key, value)
|
env_vars = "\n".join("export %s=%s" % (key, value) for (key, value)
|
||||||
@ -712,11 +712,11 @@ class SaharaAggregateValidator(SaharaImageValidatorBase):
|
|||||||
class SaharaAnyValidator(SaharaAggregateValidator):
|
class SaharaAnyValidator(SaharaAggregateValidator):
|
||||||
"""A list of validators, only one of which must succeed."""
|
"""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):
|
image_arguments=None, **kwargs):
|
||||||
results = []
|
results = []
|
||||||
for validator in self.validators:
|
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,
|
image_arguments=image_arguments,
|
||||||
**kwargs)
|
**kwargs)
|
||||||
results.append(result)
|
results.append(result)
|
||||||
@ -724,28 +724,28 @@ class SaharaAnyValidator(SaharaAggregateValidator):
|
|||||||
break
|
break
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def validate(self, remote, reconcile=True,
|
def validate(self, remote, test_only=False,
|
||||||
image_arguments=None, **kwargs):
|
image_arguments=None, **kwargs):
|
||||||
"""Attempts to validate any of the contained validators.
|
"""Attempts to validate any of the contained validators.
|
||||||
|
|
||||||
Note that if reconcile=True, this validator will first run all
|
Note that if test_only=False, this validator will first run all
|
||||||
contained validators using reconcile=False, and succeed immediately
|
contained validators using test_only=True, and succeed immediately
|
||||||
should any pass validation. If all fail, it will only then run them
|
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 remote: A remote socket to the instance.
|
||||||
:param reconcile: If false, all validators will only verify that a
|
:param test_only: If true, all validators will only verify that a
|
||||||
desired state is present, and fail if it is not. If true, all
|
desired state is present, and fail if it is not. If false, all
|
||||||
validators will attempt to enforce the desired state if possible,
|
validators will attempt to enforce the desired state if possible,
|
||||||
and succeed if this enforcement succeeds.
|
and succeed if this enforcement succeeds.
|
||||||
:param image_arguments: A dictionary of image argument values keyed by
|
:param image_arguments: A dictionary of image argument values keyed by
|
||||||
argument name.
|
argument name.
|
||||||
:raises ImageValidationError: If validation fails.
|
:raises ImageValidationError: If validation fails.
|
||||||
"""
|
"""
|
||||||
results = self._try_all(remote, reconcile=False,
|
results = self._try_all(remote, test_only=True,
|
||||||
image_arguments=image_arguments)
|
image_arguments=image_arguments)
|
||||||
if reconcile and not any(results):
|
if not test_only and not any(results):
|
||||||
results = self._try_all(remote, reconcile=True,
|
results = self._try_all(remote, test_only=False,
|
||||||
image_arguments=image_arguments)
|
image_arguments=image_arguments)
|
||||||
if not any(results):
|
if not any(results):
|
||||||
raise p_ex.AllValidationsFailedError(result.exception for result
|
raise p_ex.AllValidationsFailedError(result.exception for result
|
||||||
@ -755,12 +755,13 @@ class SaharaAnyValidator(SaharaAggregateValidator):
|
|||||||
class SaharaAllValidator(SaharaAggregateValidator):
|
class SaharaAllValidator(SaharaAggregateValidator):
|
||||||
"""A list of validators, all of which must succeed."""
|
"""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.
|
"""Attempts to validate all of the contained validators.
|
||||||
|
|
||||||
:param remote: A remote socket to the instance.
|
:param remote: A remote socket to the instance.
|
||||||
:param reconcile: If false, all validators will only verify that a
|
:param test_only: If true, all validators will only verify that a
|
||||||
desired state is present, and fail if it is not. If true, all
|
desired state is present, and fail if it is not. If false, all
|
||||||
validators will attempt to enforce the desired state if possible,
|
validators will attempt to enforce the desired state if possible,
|
||||||
and succeed if this enforcement succeeds.
|
and succeed if this enforcement succeeds.
|
||||||
:param image_arguments: A dictionary of image argument values keyed by
|
:param image_arguments: A dictionary of image argument values keyed by
|
||||||
@ -768,7 +769,7 @@ class SaharaAllValidator(SaharaAggregateValidator):
|
|||||||
:raises ImageValidationError: If validation fails.
|
:raises ImageValidationError: If validation fails.
|
||||||
"""
|
"""
|
||||||
for validator in self.validators:
|
for validator in self.validators:
|
||||||
validator.validate(remote, reconcile=reconcile,
|
validator.validate(remote, test_only=test_only,
|
||||||
image_arguments=image_arguments)
|
image_arguments=image_arguments)
|
||||||
|
|
||||||
|
|
||||||
@ -818,7 +819,7 @@ class SaharaOSCaseValidator(SaharaImageValidatorBase):
|
|||||||
"""
|
"""
|
||||||
self.distros = distros
|
self.distros = distros
|
||||||
|
|
||||||
def validate(self, remote, reconcile=True,
|
def validate(self, remote, test_only=False,
|
||||||
image_arguments=None, **kwargs):
|
image_arguments=None, **kwargs):
|
||||||
"""Attempts to validate depending on distro.
|
"""Attempts to validate depending on distro.
|
||||||
|
|
||||||
@ -828,8 +829,8 @@ class SaharaOSCaseValidator(SaharaImageValidatorBase):
|
|||||||
If no keys match, no validators are run, and validation proceeds.
|
If no keys match, no validators are run, and validation proceeds.
|
||||||
|
|
||||||
:param remote: A remote socket to the instance.
|
:param remote: A remote socket to the instance.
|
||||||
:param reconcile: If false, all validators will only verify that a
|
:param test_only: If true, all validators will only verify that a
|
||||||
desired state is present, and fail if it is not. If true, all
|
desired state is present, and fail if it is not. If false, all
|
||||||
validators will attempt to enforce the desired state if possible,
|
validators will attempt to enforce the desired state if possible,
|
||||||
and succeed if this enforcement succeeds.
|
and succeed if this enforcement succeeds.
|
||||||
:param image_arguments: A dictionary of image argument values keyed by
|
:param image_arguments: A dictionary of image argument values keyed by
|
||||||
@ -842,7 +843,7 @@ class SaharaOSCaseValidator(SaharaImageValidatorBase):
|
|||||||
for distro, validator in self.distros:
|
for distro, validator in self.distros:
|
||||||
if distro in matches:
|
if distro in matches:
|
||||||
validator.validate(
|
validator.validate(
|
||||||
remote, reconcile=reconcile,
|
remote, test_only=test_only,
|
||||||
image_arguments=image_arguments)
|
image_arguments=image_arguments)
|
||||||
break
|
break
|
||||||
|
|
||||||
@ -901,13 +902,13 @@ class SaharaArgumentCaseValidator(SaharaImageValidatorBase):
|
|||||||
self.argument_name = argument_name
|
self.argument_name = argument_name
|
||||||
self.cases = cases
|
self.cases = cases
|
||||||
|
|
||||||
def validate(self, remote, reconcile=True,
|
def validate(self, remote, test_only=False,
|
||||||
image_arguments=None, **kwargs):
|
image_arguments=None, **kwargs):
|
||||||
"""Attempts to validate depending on argument value.
|
"""Attempts to validate depending on argument value.
|
||||||
|
|
||||||
:param remote: A remote socket to the instance.
|
:param remote: A remote socket to the instance.
|
||||||
:param reconcile: If false, all validators will only verify that a
|
:param test_only: If true, all validators will only verify that a
|
||||||
desired state is present, and fail if it is not. If true, all
|
desired state is present, and fail if it is not. If false, all
|
||||||
validators will attempt to enforce the desired state if possible,
|
validators will attempt to enforce the desired state if possible,
|
||||||
and succeed if this enforcement succeeds.
|
and succeed if this enforcement succeeds.
|
||||||
:param image_arguments: A dictionary of image argument values keyed by
|
:param image_arguments: A dictionary of image argument values keyed by
|
||||||
@ -921,7 +922,7 @@ class SaharaArgumentCaseValidator(SaharaImageValidatorBase):
|
|||||||
value = image_arguments[arg]
|
value = image_arguments[arg]
|
||||||
if value in self.cases:
|
if value in self.cases:
|
||||||
self.cases[value].validate(
|
self.cases[value].validate(
|
||||||
remote, reconcile=reconcile,
|
remote, test_only=test_only,
|
||||||
image_arguments=image_arguments)
|
image_arguments=image_arguments)
|
||||||
|
|
||||||
|
|
||||||
@ -972,13 +973,13 @@ class SaharaArgumentSetterValidator(SaharaImageValidatorBase):
|
|||||||
self.argument_name = argument_name
|
self.argument_name = argument_name
|
||||||
self.value = value
|
self.value = value
|
||||||
|
|
||||||
def validate(self, remote, reconcile=True,
|
def validate(self, remote, test_only=False,
|
||||||
image_arguments=None, **kwargs):
|
image_arguments=None, **kwargs):
|
||||||
"""Attempts to validate depending on argument value.
|
"""Attempts to validate depending on argument value.
|
||||||
|
|
||||||
:param remote: A remote socket to the instance.
|
:param remote: A remote socket to the instance.
|
||||||
:param reconcile: If false, all validators will only verify that a
|
:param test_only: If true, all validators will only verify that a
|
||||||
desired state is present, and fail if it is not. If true, all
|
desired state is present, and fail if it is not. If false, all
|
||||||
validators will attempt to enforce the desired state if possible,
|
validators will attempt to enforce the desired state if possible,
|
||||||
and succeed if this enforcement succeeds.
|
and succeed if this enforcement succeeds.
|
||||||
:param image_arguments: A dictionary of image argument values keyed by
|
:param image_arguments: A dictionary of image argument values keyed by
|
||||||
|
@ -135,24 +135,24 @@ class ProvisioningPluginBase(plugins_base.PluginInterface):
|
|||||||
|
|
||||||
@plugins_base.optional
|
@plugins_base.optional
|
||||||
def pack_image(self, hadoop_version, remote,
|
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
|
"""Packs an image for registration in Glance and use by Sahara
|
||||||
|
|
||||||
:param remote: A remote (usually of type
|
:param remote: A remote (usually of type
|
||||||
sahara.cli.image_pack.api.ImageRemote) that serves as a handle to
|
sahara.cli.image_pack.api.ImageRemote) that serves as a handle to
|
||||||
the image to modify. Note that this image will be modified
|
the image to modify. Note that this image will be modified
|
||||||
in-place, not copied.
|
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.
|
ensure that the image already meets the plugin's requirements.
|
||||||
This can be used to test images without modification. If set to
|
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.
|
requirements are not met.
|
||||||
:param image_arguments: A dict of image argument name to argument
|
:param image_arguments: A dict of image argument name to argument
|
||||||
value.
|
value.
|
||||||
:raises: sahara.plugins.exceptions.ImageValidationError: If the method
|
: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
|
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:
|
:raises: sahara.plugins.exceptions.ImageValidationSpecificationError:
|
||||||
If the specification for image generation or validation is itself
|
If the specification for image generation or validation is itself
|
||||||
in error and cannot be executed without repair.
|
in error and cannot be executed without repair.
|
||||||
@ -160,22 +160,22 @@ class ProvisioningPluginBase(plugins_base.PluginInterface):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
@plugins_base.optional
|
@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.
|
"""Validates the image to be used by a cluster.
|
||||||
|
|
||||||
:param cluster: The object handle to a cluster which has active
|
:param cluster: The object handle to a cluster which has active
|
||||||
instances ready to generate remote handles.
|
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.
|
ensure that the image already meets the plugin's requirements.
|
||||||
This can be used to test images without modification. If set to
|
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.
|
requirements are not met.
|
||||||
:param image_arguments: A dict of image argument name to argument
|
:param image_arguments: A dict of image argument name to argument
|
||||||
value.
|
value.
|
||||||
:raises: sahara.plugins.exceptions.ImageValidationError: If the method
|
: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
|
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:
|
:raises: sahara.plugins.exceptions.ImageValidationSpecificationError:
|
||||||
If the specification for image generation or validation is itself
|
If the specification for image generation or validation is itself
|
||||||
in error and cannot be executed without repair.
|
in error and cannot be executed without repair.
|
||||||
|
@ -289,7 +289,7 @@ def _provision_cluster(cluster_id):
|
|||||||
cluster, c_u.CLUSTER_STATUS_CONFIGURING)
|
cluster, c_u.CLUSTER_STATUS_CONFIGURING)
|
||||||
context.set_step_type(_("Plugin: configure cluster"))
|
context.set_step_type(_("Plugin: configure cluster"))
|
||||||
if hasattr(plugin, 'validate_images'):
|
if hasattr(plugin, 'validate_images'):
|
||||||
plugin.validate_images(cluster, reconcile=True)
|
plugin.validate_images(cluster, test_only=False)
|
||||||
shares.mount_shares(cluster)
|
shares.mount_shares(cluster)
|
||||||
plugin.configure_cluster(cluster)
|
plugin.configure_cluster(cluster)
|
||||||
|
|
||||||
|
@ -47,14 +47,14 @@ class TestImages(b.SaharaTestCase):
|
|||||||
|
|
||||||
validator = cls.from_spec('test_images.py', {}, resource_roots)
|
validator = cls.from_spec('test_images.py', {}, resource_roots)
|
||||||
self.assertIsInstance(validator, cls)
|
self.assertIsInstance(validator, cls)
|
||||||
self.assertEqual(validator.env_vars, ['reconcile', 'distro'])
|
self.assertEqual(validator.env_vars, ['test_only', 'distro'])
|
||||||
|
|
||||||
validator = cls.from_spec(
|
validator = cls.from_spec(
|
||||||
{'test_images.py': {'env_vars': ['extra-file', 'user']}},
|
{'test_images.py': {'env_vars': ['extra-file', 'user']}},
|
||||||
{}, resource_roots)
|
{}, resource_roots)
|
||||||
self.assertIsInstance(validator, cls)
|
self.assertIsInstance(validator, cls)
|
||||||
self.assertEqual(validator.env_vars,
|
self.assertEqual(validator.env_vars,
|
||||||
['reconcile', 'distro',
|
['test_only', 'distro',
|
||||||
'extra-file', 'user'])
|
'extra-file', 'user'])
|
||||||
|
|
||||||
def test_all_spec(self):
|
def test_all_spec(self):
|
||||||
@ -181,7 +181,7 @@ class TestImages(b.SaharaTestCase):
|
|||||||
packages = [cls.Package("java", "8")]
|
packages = [cls.Package("java", "8")]
|
||||||
validator = images.SaharaPackageValidator(packages)
|
validator = images.SaharaPackageValidator(packages)
|
||||||
remote = mock.Mock()
|
remote = mock.Mock()
|
||||||
validator.validate(remote, reconcile=False,
|
validator.validate(remote, test_only=True,
|
||||||
image_arguments=image_arguments)
|
image_arguments=image_arguments)
|
||||||
remote.execute_command.assert_called_with(
|
remote.execute_command.assert_called_with(
|
||||||
"rpm -q java-8", run_as_root=True)
|
"rpm -q java-8", run_as_root=True)
|
||||||
@ -193,7 +193,7 @@ class TestImages(b.SaharaTestCase):
|
|||||||
remote.execute_command.side_effect = (
|
remote.execute_command.side_effect = (
|
||||||
ex.RemoteCommandException("So bad!"))
|
ex.RemoteCommandException("So bad!"))
|
||||||
try:
|
try:
|
||||||
validator.validate(remote, reconcile=False,
|
validator.validate(remote, test_only=True,
|
||||||
image_arguments=image_arguments)
|
image_arguments=image_arguments)
|
||||||
except p_ex.ImageValidationError as e:
|
except p_ex.ImageValidationError as e:
|
||||||
self.assertIn("So bad!", e.message)
|
self.assertIn("So bad!", e.message)
|
||||||
@ -212,7 +212,7 @@ class TestImages(b.SaharaTestCase):
|
|||||||
|
|
||||||
remote.execute_command.side_effect = side_effect
|
remote.execute_command.side_effect = side_effect
|
||||||
try:
|
try:
|
||||||
validator.validate(remote, reconcile=True,
|
validator.validate(remote, test_only=False,
|
||||||
image_arguments=image_arguments)
|
image_arguments=image_arguments)
|
||||||
except p_ex.ImageValidationError as e:
|
except p_ex.ImageValidationError as e:
|
||||||
self.assertIn("So bad!", e.message)
|
self.assertIn("So bad!", e.message)
|
||||||
@ -229,7 +229,7 @@ class TestImages(b.SaharaTestCase):
|
|||||||
packages = [cls.Package("java", "8")]
|
packages = [cls.Package("java", "8")]
|
||||||
validator = images.SaharaPackageValidator(packages)
|
validator = images.SaharaPackageValidator(packages)
|
||||||
remote = mock.Mock()
|
remote = mock.Mock()
|
||||||
validator.validate(remote, reconcile=False,
|
validator.validate(remote, test_only=True,
|
||||||
image_arguments=image_arguments)
|
image_arguments=image_arguments)
|
||||||
remote.execute_command.assert_called_with(
|
remote.execute_command.assert_called_with(
|
||||||
"dpkg -s java-8", run_as_root=True)
|
"dpkg -s java-8", run_as_root=True)
|
||||||
@ -241,7 +241,7 @@ class TestImages(b.SaharaTestCase):
|
|||||||
remote.execute_command.side_effect = (
|
remote.execute_command.side_effect = (
|
||||||
ex.RemoteCommandException("So bad!"))
|
ex.RemoteCommandException("So bad!"))
|
||||||
try:
|
try:
|
||||||
validator.validate(remote, reconcile=False,
|
validator.validate(remote, test_only=True,
|
||||||
image_arguments=image_arguments)
|
image_arguments=image_arguments)
|
||||||
except p_ex.ImageValidationError as e:
|
except p_ex.ImageValidationError as e:
|
||||||
self.assertIn("So bad!", e.message)
|
self.assertIn("So bad!", e.message)
|
||||||
@ -256,7 +256,7 @@ class TestImages(b.SaharaTestCase):
|
|||||||
remote.execute_command.side_effect = (
|
remote.execute_command.side_effect = (
|
||||||
ex.RemoteCommandException("So bad!"))
|
ex.RemoteCommandException("So bad!"))
|
||||||
try:
|
try:
|
||||||
validator.validate(remote, reconcile=True,
|
validator.validate(remote, test_only=False,
|
||||||
image_arguments=image_arguments)
|
image_arguments=image_arguments)
|
||||||
except p_ex.ImageValidationError as e:
|
except p_ex.ImageValidationError as e:
|
||||||
self.assertIn("So bad!", e.message)
|
self.assertIn("So bad!", e.message)
|
||||||
@ -279,7 +279,7 @@ class TestImages(b.SaharaTestCase):
|
|||||||
execute_command=mock.Mock(
|
execute_command=mock.Mock(
|
||||||
return_value=(0, 'fedora')))
|
return_value=(0, 'fedora')))
|
||||||
|
|
||||||
validator.validate(remote, reconcile=True,
|
validator.validate(remote, test_only=False,
|
||||||
image_arguments=image_arguments)
|
image_arguments=image_arguments)
|
||||||
call = [mock.call(map_rep + cmd, run_as_root=True)]
|
call = [mock.call(map_rep + cmd, run_as_root=True)]
|
||||||
remote.execute_command.assert_has_calls(call)
|
remote.execute_command.assert_has_calls(call)
|
||||||
@ -293,31 +293,31 @@ class TestImages(b.SaharaTestCase):
|
|||||||
def __init__(self, mock_validate):
|
def __init__(self, mock_validate):
|
||||||
self.mock_validate = mock_validate
|
self.mock_validate = mock_validate
|
||||||
|
|
||||||
def validate(self, remote, reconcile=True, **kwargs):
|
def validate(self, remote, test_only=False, **kwargs):
|
||||||
self.mock_validate(remote, reconcile=reconcile, **kwargs)
|
self.mock_validate(remote, test_only=test_only, **kwargs)
|
||||||
|
|
||||||
# One success short circuits validation
|
# One success short circuits validation
|
||||||
always_tells_the_truth = FakeValidator(mock.Mock())
|
always_tells_the_truth = FakeValidator(mock.Mock())
|
||||||
validator = cls([always_tells_the_truth, always_tells_the_truth])
|
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)
|
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(
|
always_lies = FakeValidator(
|
||||||
mock.Mock(side_effect=p_ex.ImageValidationError("Oh no!")))
|
mock.Mock(side_effect=p_ex.ImageValidationError("Oh no!")))
|
||||||
validator = cls([always_lies, always_lies])
|
validator = cls([always_lies, always_lies])
|
||||||
try:
|
try:
|
||||||
validator.validate(None, reconcile=True)
|
validator.validate(None, test_only=False)
|
||||||
except p_ex.ImageValidationError:
|
except p_ex.ImageValidationError:
|
||||||
pass
|
pass
|
||||||
self.assertEqual(always_lies.mock_validate.call_count, 4)
|
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(
|
always_lies = FakeValidator(
|
||||||
mock.Mock(side_effect=p_ex.ImageValidationError("Oh no!")))
|
mock.Mock(side_effect=p_ex.ImageValidationError("Oh no!")))
|
||||||
validator = cls([always_lies, always_lies])
|
validator = cls([always_lies, always_lies])
|
||||||
try:
|
try:
|
||||||
validator.validate(None, reconcile=False)
|
validator.validate(None, test_only=True)
|
||||||
except p_ex.ImageValidationError:
|
except p_ex.ImageValidationError:
|
||||||
pass
|
pass
|
||||||
self.assertEqual(always_lies.mock_validate.call_count, 2)
|
self.assertEqual(always_lies.mock_validate.call_count, 2)
|
||||||
@ -327,7 +327,7 @@ class TestImages(b.SaharaTestCase):
|
|||||||
always_lies = FakeValidator(
|
always_lies = FakeValidator(
|
||||||
mock.Mock(side_effect=p_ex.ImageValidationError("Oh no!")))
|
mock.Mock(side_effect=p_ex.ImageValidationError("Oh no!")))
|
||||||
validator = cls([always_lies, always_tells_the_truth])
|
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_lies.mock_validate.call_count, 1)
|
||||||
self.assertEqual(always_tells_the_truth.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
|
# All pass
|
||||||
always_tells_the_truth = mock.Mock()
|
always_tells_the_truth = mock.Mock()
|
||||||
validator = cls([always_tells_the_truth, always_tells_the_truth])
|
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)
|
self.assertEqual(always_tells_the_truth.validate.call_count, 2)
|
||||||
always_tells_the_truth.validate.assert_called_with(
|
always_tells_the_truth.validate.assert_called_with(
|
||||||
None, reconcile=True, image_arguments=None)
|
None, test_only=False, image_arguments=None)
|
||||||
|
|
||||||
# Second fails
|
# Second fails
|
||||||
always_tells_the_truth = mock.Mock()
|
always_tells_the_truth = mock.Mock()
|
||||||
@ -348,15 +348,15 @@ class TestImages(b.SaharaTestCase):
|
|||||||
side_effect=p_ex.ImageValidationError("Boom!")))
|
side_effect=p_ex.ImageValidationError("Boom!")))
|
||||||
validator = cls([always_tells_the_truth, always_lies])
|
validator = cls([always_tells_the_truth, always_lies])
|
||||||
try:
|
try:
|
||||||
validator.validate(None, reconcile=False)
|
validator.validate(None, test_only=True)
|
||||||
except p_ex.ImageValidationError:
|
except p_ex.ImageValidationError:
|
||||||
pass
|
pass
|
||||||
self.assertEqual(always_tells_the_truth.validate.call_count, 1)
|
self.assertEqual(always_tells_the_truth.validate.call_count, 1)
|
||||||
self.assertEqual(always_lies.validate.call_count, 1)
|
self.assertEqual(always_lies.validate.call_count, 1)
|
||||||
always_tells_the_truth.validate.assert_called_with(
|
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(
|
always_lies.validate.assert_called_with(
|
||||||
None, reconcile=False, image_arguments=None)
|
None, test_only=True, image_arguments=None)
|
||||||
|
|
||||||
# First fails
|
# First fails
|
||||||
always_tells_the_truth = mock.Mock()
|
always_tells_the_truth = mock.Mock()
|
||||||
@ -364,12 +364,12 @@ class TestImages(b.SaharaTestCase):
|
|||||||
side_effect=p_ex.ImageValidationError("Boom!")))
|
side_effect=p_ex.ImageValidationError("Boom!")))
|
||||||
validator = cls([always_lies, always_tells_the_truth])
|
validator = cls([always_lies, always_tells_the_truth])
|
||||||
try:
|
try:
|
||||||
validator.validate(None, reconcile=False, image_arguments={})
|
validator.validate(None, test_only=True, image_arguments={})
|
||||||
except p_ex.ImageValidationError:
|
except p_ex.ImageValidationError:
|
||||||
pass
|
pass
|
||||||
self.assertEqual(always_lies.validate.call_count, 1)
|
self.assertEqual(always_lies.validate.call_count, 1)
|
||||||
always_lies.validate.assert_called_with(
|
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)
|
self.assertEqual(always_tells_the_truth.validate.call_count, 0)
|
||||||
|
|
||||||
def test_os_case_validator(self):
|
def test_os_case_validator(self):
|
||||||
@ -382,12 +382,12 @@ class TestImages(b.SaharaTestCase):
|
|||||||
distros = [centos, redhat]
|
distros = [centos, redhat]
|
||||||
image_arguments = {images.SaharaImageValidator.DISTRO_KEY: "centos"}
|
image_arguments = {images.SaharaImageValidator.DISTRO_KEY: "centos"}
|
||||||
validator = cls(distros)
|
validator = cls(distros)
|
||||||
validator.validate(None, reconcile=True,
|
validator.validate(None, test_only=False,
|
||||||
image_arguments=image_arguments)
|
image_arguments=image_arguments)
|
||||||
self.assertEqual(centos.validator.validate.call_count, 1)
|
self.assertEqual(centos.validator.validate.call_count, 1)
|
||||||
self.assertEqual(redhat.validator.validate.call_count, 0)
|
self.assertEqual(redhat.validator.validate.call_count, 0)
|
||||||
centos.validator.validate.assert_called_with(
|
centos.validator.validate.assert_called_with(
|
||||||
None, reconcile=True, image_arguments=image_arguments)
|
None, test_only=False, image_arguments=image_arguments)
|
||||||
|
|
||||||
# Families match
|
# Families match
|
||||||
centos = Distro("centos", mock.Mock())
|
centos = Distro("centos", mock.Mock())
|
||||||
@ -395,12 +395,12 @@ class TestImages(b.SaharaTestCase):
|
|||||||
distros = [centos, redhat]
|
distros = [centos, redhat]
|
||||||
image_arguments = {images.SaharaImageValidator.DISTRO_KEY: "fedora"}
|
image_arguments = {images.SaharaImageValidator.DISTRO_KEY: "fedora"}
|
||||||
validator = cls(distros)
|
validator = cls(distros)
|
||||||
validator.validate(None, reconcile=True,
|
validator.validate(None, test_only=False,
|
||||||
image_arguments=image_arguments)
|
image_arguments=image_arguments)
|
||||||
self.assertEqual(centos.validator.validate.call_count, 0)
|
self.assertEqual(centos.validator.validate.call_count, 0)
|
||||||
self.assertEqual(redhat.validator.validate.call_count, 1)
|
self.assertEqual(redhat.validator.validate.call_count, 1)
|
||||||
redhat.validator.validate.assert_called_with(
|
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
|
# Non-matches do nothing
|
||||||
centos = Distro("centos", mock.Mock())
|
centos = Distro("centos", mock.Mock())
|
||||||
@ -408,7 +408,7 @@ class TestImages(b.SaharaTestCase):
|
|||||||
distros = [centos, redhat]
|
distros = [centos, redhat]
|
||||||
image_arguments = {images.SaharaImageValidator.DISTRO_KEY: "ubuntu"}
|
image_arguments = {images.SaharaImageValidator.DISTRO_KEY: "ubuntu"}
|
||||||
validator = cls(distros)
|
validator = cls(distros)
|
||||||
validator.validate(None, reconcile=True,
|
validator.validate(None, test_only=False,
|
||||||
image_arguments=image_arguments)
|
image_arguments=image_arguments)
|
||||||
self.assertEqual(centos.validator.validate.call_count, 0)
|
self.assertEqual(centos.validator.validate.call_count, 0)
|
||||||
self.assertEqual(redhat.validator.validate.call_count, 0)
|
self.assertEqual(redhat.validator.validate.call_count, 0)
|
||||||
@ -423,12 +423,12 @@ class TestImages(b.SaharaTestCase):
|
|||||||
cases = {"value": match,
|
cases = {"value": match,
|
||||||
"another_value": nomatch}
|
"another_value": nomatch}
|
||||||
validator = cls("argument", cases)
|
validator = cls("argument", cases)
|
||||||
validator.validate(None, reconcile=True,
|
validator.validate(None, test_only=False,
|
||||||
image_arguments=image_arguments)
|
image_arguments=image_arguments)
|
||||||
self.assertEqual(match.validate.call_count, 1)
|
self.assertEqual(match.validate.call_count, 1)
|
||||||
self.assertEqual(nomatch.validate.call_count, 0)
|
self.assertEqual(nomatch.validate.call_count, 0)
|
||||||
match.validate.assert_called_with(
|
match.validate.assert_called_with(
|
||||||
None, reconcile=True, image_arguments=image_arguments)
|
None, test_only=False, image_arguments=image_arguments)
|
||||||
|
|
||||||
# Non-matches do nothing
|
# Non-matches do nothing
|
||||||
image_arguments = {"argument": "value"}
|
image_arguments = {"argument": "value"}
|
||||||
@ -436,7 +436,7 @@ class TestImages(b.SaharaTestCase):
|
|||||||
cases = {"some_value": nomatch,
|
cases = {"some_value": nomatch,
|
||||||
"another_value": nomatch}
|
"another_value": nomatch}
|
||||||
validator = cls("argument", cases)
|
validator = cls("argument", cases)
|
||||||
validator.validate(None, reconcile=True,
|
validator.validate(None, test_only=False,
|
||||||
image_arguments=image_arguments)
|
image_arguments=image_arguments)
|
||||||
self.assertEqual(nomatch.validate.call_count, 0)
|
self.assertEqual(nomatch.validate.call_count, 0)
|
||||||
|
|
||||||
@ -446,14 +446,14 @@ class TestImages(b.SaharaTestCase):
|
|||||||
# Old variable is overwritten
|
# Old variable is overwritten
|
||||||
image_arguments = {"argument": "value"}
|
image_arguments = {"argument": "value"}
|
||||||
validator = cls("argument", "new_value")
|
validator = cls("argument", "new_value")
|
||||||
validator.validate(None, reconcile=True,
|
validator.validate(None, test_only=False,
|
||||||
image_arguments=image_arguments)
|
image_arguments=image_arguments)
|
||||||
self.assertEqual(image_arguments["argument"], "new_value")
|
self.assertEqual(image_arguments["argument"], "new_value")
|
||||||
|
|
||||||
# New variable is set
|
# New variable is set
|
||||||
image_arguments = {"argument": "value"}
|
image_arguments = {"argument": "value"}
|
||||||
validator = cls("another_argument", "value")
|
validator = cls("another_argument", "value")
|
||||||
validator.validate(None, reconcile=True,
|
validator.validate(None, test_only=False,
|
||||||
image_arguments=image_arguments)
|
image_arguments=image_arguments)
|
||||||
self.assertEqual(image_arguments,
|
self.assertEqual(image_arguments,
|
||||||
{"argument": "value", "another_argument": "value"})
|
{"argument": "value", "another_argument": "value"})
|
||||||
@ -465,11 +465,11 @@ class TestImages(b.SaharaTestCase):
|
|||||||
remote = mock.Mock(get_os_distrib=mock.Mock(
|
remote = mock.Mock(get_os_distrib=mock.Mock(
|
||||||
return_value="centos"))
|
return_value="centos"))
|
||||||
validator = cls(sub_validator, {})
|
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"}
|
expected_map = {images.SaharaImageValidatorBase.DISTRO_KEY: "centos"}
|
||||||
sub_validator.validate.assert_called_with(
|
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"}
|
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(
|
sub_validator.validate.assert_called_with(
|
||||||
remote, reconcile=False, image_arguments=expected_map)
|
remote, test_only=True, image_arguments=expected_map)
|
||||||
|
Loading…
Reference in New Issue
Block a user