Add tests for IBP

Add tests for Image Based Provisioning
+Add test default packages are installed after node provisioning
+Add test adding package to list installs it
+Add test removing package from list doesn't install it
+Add test adding wrong package name breaks provisioning

Related-bug: #1538140

Change-Id: I71b89b7e14547031eb207f89fab0cc6bab788330
This commit is contained in:
Volodymyr Shypyguzov 2016-04-21 17:17:46 +03:00
parent cec46a07ad
commit 7f6977c52b
4 changed files with 272 additions and 0 deletions

View File

@ -721,3 +721,9 @@ Test for multipath devices
--------------------------
.. automodule:: fuelweb_test.tests.test_multipath_devices
:members:
Test for Image Based Provisioning
---------------------------------
.. automodule:: fuelweb_test.tests.tests_ibp.test_ibp
:members:

View File

@ -2775,6 +2775,20 @@ class FuelWebClient29(object):
components[comp] = opts['value']
return components
@logwrap
def get_cluster_ibp_packages(self, cluster_id):
attributes = self.client.get_cluster_attributes(cluster_id)
pkgs = attributes['editable']['provision']['packages']['value']
return set(pkgs.splitlines())
@logwrap
def update_cluster_ibp_packages(self, cluster_id, pkgs):
attributes = self.client.get_cluster_attributes(cluster_id)
attributes['editable']['provision']['packages']['value'] = '\n'.join(
pkgs)
self.client.update_cluster_attributes(cluster_id, attributes)
return self.get_cluster_ibp_packages(cluster_id)
@logwrap
def spawn_vms_wait(self, cluster_id, timeout=60 * 60, interval=30):
logger.info('Spawn VMs of a cluster %s', cluster_id)

View File

View File

@ -0,0 +1,252 @@
# Copyright 2016 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from proboscis import test
from proboscis.asserts import assert_true
from fuelweb_test.helpers.decorators import log_snapshot_after_test
from fuelweb_test import logger
from fuelweb_test.tests.base_test_case import SetupEnvironment
from fuelweb_test.tests.base_test_case import TestBasic
@test(groups=["test_ibp"])
class IBPTest(TestBasic):
"""IBP test.""" # TODO(vshypyguzov) documentation
def check_node_packages(self, node_name, pkg_list):
node_ip = self.fuel_web.get_nailgun_node_by_base_name(node_name)['ip']
cmd = "dpkg-query -W -f='\${Package}'\r"
node_pkgs = self.ssh_manager.execute_on_remote(
node_ip,
cmd)['stdout_str'].splitlines()
node_pkgs = set(node_pkgs)
logger.debug('Node packages are: {}'.format(node_pkgs))
assert_true(
pkg_list.issubset(node_pkgs),
'Not all packages are present on node.'
' Missing packages: {}'.format(pkg_list - node_pkgs)
)
@test(depends_on=[SetupEnvironment.prepare_slaves_1],
groups=["check_ibp_default_package_list"])
@log_snapshot_after_test
def check_ibp_default_package_list(self):
"""Provision one node with default package list
Scenario:
1. Create cluster
2. Add one node to cluster
3. Provision nodes
4. Check that all default packages are installed on the node
Duration 60m
Snapshot check_ibp_default_package_list
"""
self.env.revert_snapshot("ready_with_1_slaves")
self.show_step(1)
cluster_id = self.fuel_web.create_cluster(
name=self.__class__.__name__
)
pkg_list = self.fuel_web.get_cluster_ibp_packages(cluster_id)
logger.debug('Cluster IBP packages: {}'.format(pkg_list))
self.show_step(2)
self.fuel_web.update_nodes(
cluster_id,
{
'slave-01': ['controller'],
}
)
self.show_step(3)
self.fuel_web.provisioning_cluster_wait(cluster_id)
self.show_step(4)
self.check_node_packages('slave-01', pkg_list)
self.env.make_snapshot("check_ibp_default_package_list")
@test(depends_on=[SetupEnvironment.prepare_slaves_1],
groups=["check_ibp_add_package"])
@log_snapshot_after_test
def check_ibp_add_package(self):
"""Add package to package list and provision one node. Check that
added package is installed.
Scenario:
1. Create cluster
2. Add one package to the initial packages list
3. Add one node to cluster
4. Provision nodes
5. Check that all packages including added one are installed
Duration 60m
Snapshot check_ibp_add_package
"""
self.env.revert_snapshot("ready_with_1_slaves")
self.show_step(1)
cluster_id = self.fuel_web.create_cluster(
name=self.__class__.__name__
)
self.show_step(2)
pkg_list = self.fuel_web.get_cluster_ibp_packages(cluster_id)
logger.debug(
'Cluster IBP packages before update: {}'.format(sorted(pkg_list))
)
pkg_to_add = 'lynx'
assert_true(
pkg_to_add not in pkg_list,
message='{} is already present in package list'.format(pkg_to_add)
)
logger.debug(
'Adding {} to the initial packages list'.format(pkg_to_add)
)
pkg_list.add(pkg_to_add)
pkg_list = self.fuel_web.update_cluster_ibp_packages(
cluster_id, pkg_list)
logger.debug(
'Cluster IBP packages after update: {}'.format(sorted(pkg_list))
)
self.show_step(3)
self.fuel_web.update_nodes(
cluster_id,
{
'slave-01': ['controller'],
}
)
self.show_step(4)
self.fuel_web.provisioning_cluster_wait(cluster_id)
self.show_step(5)
self.check_node_packages('slave-01', pkg_list)
self.env.make_snapshot("check_ibp_add_package")
@test(depends_on=[SetupEnvironment.prepare_slaves_1],
groups=["check_ibp_remove_package"])
@log_snapshot_after_test
def check_ibp_remove_package(self):
"""Remove package from package list and provision one node. Check that
removed package is not installed.
Scenario:
1. Create cluster
2. Remove one package from the initial packages list
3. Add one node to cluster
4. Provision nodes
5. Check that all packages besides removed are installed
Duration 60m
Snapshot check_ibp_remove_package
"""
self.env.revert_snapshot("ready_with_1_slaves")
self.show_step(1)
cluster_id = self.fuel_web.create_cluster(
name=self.__class__.__name__
)
self.show_step(2)
pkg_list = self.fuel_web.get_cluster_ibp_packages(cluster_id)
logger.debug(
'Cluster IBP packages before update: {}'.format(sorted(pkg_list))
)
pkg_for_removal = pkg_list.pop()
logger.debug('Removing {} from the initial packages list'.format(
pkg_for_removal))
pkg_list = self.fuel_web.update_cluster_ibp_packages(
cluster_id, pkg_list)
logger.debug(
'Cluster IBP packages after update: {}'.format(sorted(pkg_list))
)
self.show_step(3)
self.fuel_web.update_nodes(
cluster_id,
{
'slave-01': ['controller'],
}
)
self.show_step(4)
self.fuel_web.provisioning_cluster_wait(cluster_id)
self.show_step(5)
self.check_node_packages('slave-01', pkg_list)
self.env.make_snapshot("check_ibp_remove_package")
@test(depends_on=[SetupEnvironment.prepare_slaves_1],
groups=["check_ibp_add_wrong_package"])
@log_snapshot_after_test
def check_ibp_add_wrong_package(self):
"""Add package with wrong name to package list and provision one node.
Check that provision ends with error.
Scenario:
1. Create cluster
2. Add one package to the initial packages list
3. Add one node to cluster
4. Provision nodes
5. Check that provisioning ends with error
Duration 60m
Snapshot check_ibp_add_wrong_package
"""
self.env.revert_snapshot("ready_with_1_slaves")
self.show_step(1)
cluster_id = self.fuel_web.create_cluster(
name=self.__class__.__name__
)
self.show_step(2)
default_pkg_list = self.fuel_web.get_cluster_ibp_packages(cluster_id)
logger.debug(
'Cluster IBP packages before update: {}'.format(
sorted(default_pkg_list)
)
)
logger.debug('Adding non-existent-pckg to the initial packages list')
default_pkg_list.add('non-existent-pckg')
pkg_list = self.fuel_web.update_cluster_ibp_packages(
cluster_id, default_pkg_list)
default_pkg_list.remove('non-existent-pckg')
logger.debug(
'Cluster IBP packages after update: {}'.format(sorted(pkg_list))
)
self.show_step(3)
self.fuel_web.update_nodes(
cluster_id,
{
'slave-01': ['controller'],
}
)
self.show_step(4)
task = self.fuel_web.client.provision_nodes(cluster_id)
self.show_step(5)
self.fuel_web.assert_task_failed(task)
self.env.make_snapshot("check_ibp_add_wrong_package")