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
# Try to guess environment config for reverted snapshot
if revert_snapshot and config.ccp.os_host == '0.0.0.0':
config.ccp.os_host = config.k8s.kube_host
# If no snapshot was reverted, then try to revert the snapshot
# that belongs to the fixture.
# 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
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:
@pytest.mark.revert_snapshot("k8s_deployed")
"""
# Try to guess environment config for reverted snapshot
if revert_snapshot and config.k8s.kube_host == '0.0.0.0':
config.k8s.kube_host = underlay.host_by_node_name(
underlay.node_names()[0])
# If no snapshot was reverted, then try to revert the snapshot
# that belongs to the fixture.
# Note: keep fixtures in strict dependences from each other!
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
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)
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)
return snapshot_name
@ -163,10 +165,13 @@ def underlay(request, revert_snapshot, config, hardware):
- provide SSH access to underlay nodes using
node names or node IPs.
"""
# Try to guess environment config for reverted snapshot
if revert_snapshot and not config.underlay.ssh:
config.underlay.ssh = hardware.get_ssh_data(
roles=config.underlay.roles)
# If no snapshot was reverted, then try to revert the snapshot
# that belongs to the fixture.
# Note: keep fixtures in strict dependences from each other!
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
if not config.underlay.ssh:

View File

@ -12,6 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import os
from devops import error
from devops.helpers import helpers
from devops import models
@ -177,6 +179,15 @@ class EnvironmentManager(object):
raise exceptions.EnvironmentIsNotSet()
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):
"""Revert snapshot by name
@ -196,8 +207,9 @@ class EnvironmentManager(object):
raise exceptions.EnvironmentIsNotSet()
try:
settings_oslo.reload_snapshot_config(self.__config, name,
self._env.name)
test_config_path = self._get_snapshot_config_name(name)
settings_oslo.reload_snapshot_config(self.__config,
test_config_path)
except cfg.ConfigFilesNotFoundError as conf_err:
LOG.error("Config file(s) {0} not found!".format(
conf_err.config_files))
@ -274,6 +286,10 @@ class EnvironmentManager(object):
def has_snapshot(self, 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):
"""Delete environment

View File

@ -12,8 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
from oslo_config import cfg
from fuel_ccp_tests import settings_oslo
@ -80,11 +78,6 @@ class EnvironmentManagerEmpty(object):
raise Exception(
"EnvironmentManagerEmpty cannot revert nodes from {} to {}"
.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):
"""Start environment"""
@ -105,6 +98,9 @@ class EnvironmentManagerEmpty(object):
def has_snapshot(self, 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):
"""Delete environment"""
pass

View File

@ -155,12 +155,8 @@ def load_config(config_files):
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"""
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])
return config