Revert snapshots in each fixture as a workaround

If @pytest.mark.revert_snapshot(name=<some_name>) is used for
test case, but the snapshot *or* it's config is missing in the
environment, then each fixture will try to revert the snapshot
that belongs to the fixture.

Change-Id: I819dba2e775f5be38ea8cd12c6909b2e7399e3a8
This commit is contained in:
Dennis Dmitriev 2016-09-16 15:03:01 +03:00
parent 7e49f05f54
commit 2cac42dd09
6 changed files with 46 additions and 26 deletions

View File

@ -59,9 +59,13 @@ def ccpcluster(revert_snapshot, config, hardware,
ccp_actions.default_params = settings.CCP_CLI_PARAMS ccp_actions.default_params = settings.CCP_CLI_PARAMS
# Try to guess environment config for reverted snapshot # If no snapshot was reverted, then try to revert the snapshot
if revert_snapshot and config.ccp.os_host == '0.0.0.0': # that belongs to the fixture.
config.ccp.os_host = config.k8s.kube_host # Note: keep fixtures in strict dependences from each other!
if not revert_snapshot:
if hardware.has_snapshot(ext.SNAPSHOT.ccp_deployed) and \
hardware.has_snapshot_config(ext.SNAPSHOT.ccp_deployed):
hardware.revert_snapshot(ext.SNAPSHOT.ccp_deployed)
# Install CCP # Install CCP
if config.ccp.os_host == '0.0.0.0': if config.ccp.os_host == '0.0.0.0':

View File

@ -60,10 +60,13 @@ def k8scluster(revert_snapshot, request, config,
If you want to revert 'k8s_deployed' snapshot, please use mark: If you want to revert 'k8s_deployed' snapshot, please use mark:
@pytest.mark.revert_snapshot("k8s_deployed") @pytest.mark.revert_snapshot("k8s_deployed")
""" """
# Try to guess environment config for reverted snapshot # If no snapshot was reverted, then try to revert the snapshot
if revert_snapshot and config.k8s.kube_host == '0.0.0.0': # that belongs to the fixture.
config.k8s.kube_host = underlay.host_by_node_name( # Note: keep fixtures in strict dependences from each other!
underlay.node_names()[0]) if not revert_snapshot:
if hardware.has_snapshot(ext.SNAPSHOT.k8s_deployed) and \
hardware.has_snapshot_config(ext.SNAPSHOT.k8s_deployed):
hardware.revert_snapshot(ext.SNAPSHOT.k8s_deployed)
# Create k8s cluster # Create k8s cluster
if config.k8s.kube_host == '0.0.0.0': if config.k8s.kube_host == '0.0.0.0':

View File

@ -105,7 +105,9 @@ def revert_snapshot(request, hardware):
revert_snapshot = request.keywords.get('revert_snapshot', None) revert_snapshot = request.keywords.get('revert_snapshot', None)
snapshot_name = extract_name_from_mark(revert_snapshot) snapshot_name = extract_name_from_mark(revert_snapshot)
if snapshot_name and hardware.has_snapshot(snapshot_name): if snapshot_name and \
hardware.has_snapshot(snapshot_name) and \
hardware.has_snapshot_config(snapshot_name):
hardware.revert_snapshot(snapshot_name) hardware.revert_snapshot(snapshot_name)
return snapshot_name return snapshot_name
@ -163,10 +165,13 @@ def underlay(request, revert_snapshot, config, hardware):
- provide SSH access to underlay nodes using - provide SSH access to underlay nodes using
node names or node IPs. node names or node IPs.
""" """
# Try to guess environment config for reverted snapshot # If no snapshot was reverted, then try to revert the snapshot
if revert_snapshot and not config.underlay.ssh: # that belongs to the fixture.
config.underlay.ssh = hardware.get_ssh_data( # Note: keep fixtures in strict dependences from each other!
roles=config.underlay.roles) if not revert_snapshot:
if hardware.has_snapshot(ext.SNAPSHOT.underlay) and \
hardware.has_snapshot_config(ext.SNAPSHOT.underlay):
hardware.revert_snapshot(ext.SNAPSHOT.underlay)
# Create Underlay # Create Underlay
if not config.underlay.ssh: if not config.underlay.ssh:

View File

@ -12,6 +12,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import os
from devops import error from devops import error
from devops.helpers import helpers from devops.helpers import helpers
from devops import models from devops import models
@ -177,6 +179,15 @@ class EnvironmentManager(object):
raise exceptions.EnvironmentIsNotSet() raise exceptions.EnvironmentIsNotSet()
settings_oslo.save_config(self.__config, name, self._env.name) settings_oslo.save_config(self.__config, name, self._env.name)
def _get_snapshot_config_name(self, snapshot_name):
"""Get config name for the environment"""
env_name = self._env.name
if env_name is None:
env_name = 'config'
test_config_path = os.path.join(
settings.LOGS_DIR, '{0}_{1}.ini'.format(env_name, snapshot_name))
return test_config_path
def revert_snapshot(self, name): def revert_snapshot(self, name):
"""Revert snapshot by name """Revert snapshot by name
@ -196,8 +207,9 @@ class EnvironmentManager(object):
raise exceptions.EnvironmentIsNotSet() raise exceptions.EnvironmentIsNotSet()
try: try:
settings_oslo.reload_snapshot_config(self.__config, name, test_config_path = self._get_snapshot_config_name(name)
self._env.name) settings_oslo.reload_snapshot_config(self.__config,
test_config_path)
except cfg.ConfigFilesNotFoundError as conf_err: except cfg.ConfigFilesNotFoundError as conf_err:
LOG.error("Config file(s) {0} not found!".format( LOG.error("Config file(s) {0} not found!".format(
conf_err.config_files)) conf_err.config_files))
@ -274,6 +286,10 @@ class EnvironmentManager(object):
def has_snapshot(self, name): def has_snapshot(self, name):
return self._env.has_snapshot(name) return self._env.has_snapshot(name)
def has_snapshot_config(self, name):
test_config_path = self._get_snapshot_config_name(name)
return os.path.isfile(test_config_path)
def delete_environment(self): def delete_environment(self):
"""Delete environment """Delete environment

View File

@ -12,8 +12,6 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from oslo_config import cfg
from fuel_ccp_tests import settings_oslo from fuel_ccp_tests import settings_oslo
@ -80,11 +78,6 @@ class EnvironmentManagerEmpty(object):
raise Exception( raise Exception(
"EnvironmentManagerEmpty cannot revert nodes from {} to {}" "EnvironmentManagerEmpty cannot revert nodes from {} to {}"
.format(self.__config.hardware.current_snapshot, name)) .format(self.__config.hardware.current_snapshot, name))
try:
settings_oslo.reload_snapshot_config(self.__config, name)
except cfg.ConfigFilesNotFoundError:
pass
self.__config.hardware.current_snapshot = name
def start(self): def start(self):
"""Start environment""" """Start environment"""
@ -105,6 +98,9 @@ class EnvironmentManagerEmpty(object):
def has_snapshot(self, name): def has_snapshot(self, name):
return self.__config.hardware.current_snapshot == name return self.__config.hardware.current_snapshot == name
def has_snapshot_config(self, name):
return self.__config.hardware.current_snapshot == name
def delete_environment(self): def delete_environment(self):
"""Delete environment""" """Delete environment"""
pass pass

View File

@ -155,12 +155,8 @@ def load_config(config_files):
return config return config
def reload_snapshot_config(config, snapshot_name, env_name=None): def reload_snapshot_config(config, test_config_path):
"""Reset config to the state from test_config file""" """Reset config to the state from test_config file"""
if env_name is None:
env_name = 'config'
test_config_path = os.path.join(
settings.LOGS_DIR, '{0}_{1}.ini'.format(env_name, snapshot_name))
config(args=[], default_config_files=[test_config_path]) config(args=[], default_config_files=[test_config_path])
return config return config