Using methods from ccp.py manager for deployment
Fix test_fuel_ccp_deploy_microservices due to changes in ccp.py manager Change-Id: Ie91b4dd24000da8e0d881367ae61cfdda049fa0e
This commit is contained in:
parent
c8f73d12d9
commit
c412565eec
|
@ -12,13 +12,25 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from devops.helpers import helpers
|
||||
from fuel_ccp_tests import logger
|
||||
|
||||
LOG = logger.logger
|
||||
|
||||
|
||||
# TODO: replace check with deployment status request
|
||||
def check_pods_status(k8sclient, timeout=600, namespace='ccp'):
|
||||
LOG.info("Check pods status")
|
||||
|
||||
def is_pod_running(cluster, pod_name, namespace=namespace):
|
||||
return lambda: (cluster.pods.get(name=pod_name, namespace=namespace)
|
||||
._data).to_dict()['status']['phase'] == 'Running'
|
||||
def temporary_status():
|
||||
pod = cluster.pods.get(name=pod_name, namespace=namespace)
|
||||
if pod.status.phase in ['Running', 'Succeeded']:
|
||||
return True
|
||||
elif pod.status.phase == "Failed":
|
||||
if pod.status.reason == 'NodeSelectorMismatching':
|
||||
return True
|
||||
return False
|
||||
return temporary_status
|
||||
pod_names = [pod.name for pod in k8sclient.pods.list(namespace=namespace)]
|
||||
for pod_name in pod_names:
|
||||
predicate = is_pod_running(k8sclient, pod_name)
|
||||
|
@ -29,12 +41,14 @@ def check_pods_status(k8sclient, timeout=600, namespace='ccp'):
|
|||
|
||||
# TODO: replace check with deployment status request
|
||||
def check_jobs_status(k8sclient, timeout=600, namespace='ccp'):
|
||||
def is_job_running(cluster, job_name, namespace=namespace):
|
||||
return lambda: (cluster.jobs.get(name=job_name, namespace=namespace)
|
||||
._data).to_dict()['status']['succeeded'] == 'Running'
|
||||
LOG.info("Check jobs status")
|
||||
|
||||
def is_job_successful(cluster, job_name, namespace=namespace):
|
||||
return lambda: (cluster.jobs.get(
|
||||
name=job_name, namespace=namespace)).status.succeeded == 1
|
||||
job_names = [job.name for job in k8sclient.jobs.list(namespace=namespace)]
|
||||
for job_name in job_names:
|
||||
predicate = is_job_running(k8sclient, job_name)
|
||||
predicate = is_job_successful(k8sclient, job_name)
|
||||
helpers.wait(predicate, timeout=timeout,
|
||||
timeout_msg='Timeout waiting job {0} '
|
||||
'status is not successful'.format(job_name))
|
||||
|
|
|
@ -62,12 +62,24 @@ class CCPManager(object):
|
|||
cmd = self.build_command(*args, **kwargs) + " build"
|
||||
with self.__underlay.remote(
|
||||
host=self.__config.k8s.kube_host) as remote:
|
||||
LOG.info(
|
||||
"Running command '{cmd}' on node {node}".format(
|
||||
cmd=cmd,
|
||||
node=remote.hostname
|
||||
)
|
||||
)
|
||||
remote.execute(cmd)
|
||||
|
||||
def do_deploy(self, *args, **kwargs):
|
||||
cmd = self.build_command(*args, **kwargs) + " deploy"
|
||||
with self.__underlay.remote(
|
||||
host=self.__config.k8s.kube_host) as remote:
|
||||
LOG.info(
|
||||
"Running command '{cmd}' on node {node}".format(
|
||||
cmd=cmd,
|
||||
node=remote.hostname
|
||||
)
|
||||
)
|
||||
remote.execute(cmd)
|
||||
|
||||
def update_service(self, service_name):
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
ccp-microservices-options:
|
||||
- --images-base-distro debian
|
||||
- --images-maintainer mos-microservices@mirantis.com
|
||||
- --repositories-protocol https
|
||||
- --repositories-port 443
|
||||
- --builder-push
|
||||
- --registry-address {registry_address}
|
||||
- --logfile /var/log/microservices.log
|
||||
- --verbose
|
||||
- --debug
|
||||
- --builder-workers 1
|
||||
- --registry-insecure
|
||||
- --images-tag {images_tag}
|
||||
- --deploy-config ~/k8s_topology.yaml
|
||||
- --images-namespace {images_namespace}
|
||||
- build
|
||||
- deploy
|
||||
- images-base-distro: debian
|
||||
- images-maintainer: mos-microservices@mirantis.com
|
||||
- repositories-protocol: https
|
||||
- repositories-port: 443
|
||||
- builder-push
|
||||
- registry-address: {registry_address}
|
||||
- logfile: /var/log/microservices.log
|
||||
- verbose
|
||||
- debug
|
||||
- builder-workers: 1
|
||||
- registry-insecure
|
||||
- images-tag: {images_tag}
|
||||
- deploy-config: {deploy_config}
|
||||
- images-namespace: {images_namespace}
|
||||
|
|
|
@ -27,54 +27,29 @@ LOG = logger.logger
|
|||
|
||||
class TestDeployOpenstack(base_test.SystemBaseTest):
|
||||
"""Create VMs for mcpinstaller"""
|
||||
|
||||
snapshot_microservices_deployed = 'snapshot_microservices_deployed'
|
||||
kube_settings = {
|
||||
"kube_network_plugin": "calico",
|
||||
"kube_proxy_mode": "iptables",
|
||||
"hyperkube_image_repo": "quay.io/coreos/hyperkube",
|
||||
"hyperkube_image_tag": "{0}_coreos.0".format(settings.KUBE_VERSION),
|
||||
"kube_version": settings.KUBE_VERSION,
|
||||
"ipip": settings.IPIP_USAGE,
|
||||
"images_namespace": settings.IMAGES_NAMESPACE,
|
||||
"docker_options": settings.REGISTRY,
|
||||
"docker_options": "--insecure-registry={0}".format(settings.REGISTRY),
|
||||
"upstream_dns_servers": settings.UPSTREAM_DNS,
|
||||
}
|
||||
|
||||
def get_params(self, params_list, exclude_list):
|
||||
params = [param for param in params_list if param not in exclude_list]
|
||||
return params
|
||||
|
||||
def create_registry(self, remote):
|
||||
registry_pod = os.path.join(
|
||||
os.getcwd(),
|
||||
'/fuel_ccp_tests/templates/registry_templates/registry-pod.yaml')
|
||||
service_registry = os.path.join(
|
||||
os.getcwd(),
|
||||
'/fuel_ccp_tests/templates/registry_templates/'
|
||||
'service-registry.yaml')
|
||||
for item in registry_pod, service_registry:
|
||||
remote.upload(item, './')
|
||||
command = [
|
||||
'kubectl create -f ~/{0}'.format(registry_pod.split('/')[-1]),
|
||||
'kubectl create -f ~/{0}'.format(
|
||||
service_registry.split('/')[-1]),
|
||||
]
|
||||
for cmd in command:
|
||||
LOG.info(
|
||||
"Running command '{cmd}' on node {node}".format(
|
||||
cmd=cmd,
|
||||
node=remote.hostname
|
||||
)
|
||||
)
|
||||
result = remote.execute(cmd)
|
||||
assert result['exit_code'] == 0
|
||||
def get_params(self, params_list, exclude_list=None):
|
||||
params = []
|
||||
for item in params_list:
|
||||
if isinstance(item, dict):
|
||||
if item.keys()[0] not in exclude_list:
|
||||
params.append(item)
|
||||
else:
|
||||
if item not in exclude_list:
|
||||
params.append(item)
|
||||
params_dict = {}
|
||||
for item in filter(
|
||||
lambda x: isinstance(x, dict), params):
|
||||
params_dict.update(item)
|
||||
params_list = [item for item in params if not isinstance(
|
||||
item, dict)]
|
||||
return params_list, params_dict
|
||||
|
||||
def pre_build_deploy_step(self, remote):
|
||||
topology_path = os.path.join(
|
||||
os.getcwd(),
|
||||
'/fuel_ccp_tests/templates/k8s_templates/k8s_topology.yaml')
|
||||
'fuel_ccp_tests/templates/k8s_templates/k8s_topology.yaml')
|
||||
remote.upload(topology_path, './')
|
||||
command = '>/var/log/microservices.log'
|
||||
with remote.get_sudo(remote):
|
||||
|
@ -90,8 +65,8 @@ class TestDeployOpenstack(base_test.SystemBaseTest):
|
|||
@pytest.mark.snapshot_needed(name=snapshot_microservices_deployed)
|
||||
@pytest.mark.revert_snapshot(ext.SNAPSHOT.initial)
|
||||
@pytest.mark.fail_snapshot
|
||||
def test_fuel_ccp_deploy_microservices(self, config, underlay,
|
||||
k8s_actions, ccp_actions):
|
||||
def test_fuel_ccp_deploy_microservices(self, config, underlay, ccpcluster,
|
||||
k8scluster):
|
||||
"""Deploy base environment
|
||||
|
||||
Scenario:
|
||||
|
@ -100,79 +75,37 @@ class TestDeployOpenstack(base_test.SystemBaseTest):
|
|||
3. Deploy environment
|
||||
4. Check deployment
|
||||
|
||||
Duration 30 min
|
||||
Duration 35 min
|
||||
"""
|
||||
k8s_actions.install_k8s(custom_yaml=self.kube_settings)
|
||||
ccp_actions.install_ccp()
|
||||
k8sclient = k8s_actions.get_k8sclient()
|
||||
|
||||
k8sclient = k8scluster.get_k8sclient()
|
||||
remote = underlay.remote(host=config.k8s.kube_host)
|
||||
self.pre_build_deploy_step(remote)
|
||||
|
||||
registry = None
|
||||
yaml_path = os.path.join(
|
||||
os.getcwd(),
|
||||
'fuel_ccp_tests/templates/k8s_templates/build-deploy_cluster.yaml')
|
||||
with open(yaml_path, 'r') as yaml_path:
|
||||
data = yaml_path.read()
|
||||
data = data.format(registry_address='127.0.0.1:31500'
|
||||
if settings.BUILD_IMAGES else settings.REGISTRY,
|
||||
images_namespace=settings.IMAGES_NAMESPACE,
|
||||
images_tag=settings.IMAGES_TAG,
|
||||
deploy_config='~/k8s_topology.yaml')
|
||||
data_params = yaml.load(data)['ccp-microservices-options']
|
||||
if settings.BUILD_IMAGES:
|
||||
registry = '127.0.0.1:31500'
|
||||
self.create_registry(remote)
|
||||
exclude_list = ['deploy']
|
||||
yaml_path = os.path.join(
|
||||
os.getcwd(),
|
||||
'/fuel_ccp_tests/templates/'
|
||||
'k8s_templates/build-deploy_cluster.yaml')
|
||||
with open(yaml_path, 'r') as yaml_path:
|
||||
params_list = yaml.load(yaml_path)['ccp-microservices-options']
|
||||
params = self.get_params(params_list, exclude_list)
|
||||
data = ' '.join(params)
|
||||
data = data.format(registry_address=registry,
|
||||
images_namespace=settings.IMAGES_NAMESPACE,
|
||||
images_tag=settings.IMAGES_TAG)
|
||||
command = [
|
||||
'ccp {0}'.format(data)
|
||||
]
|
||||
k8scluster.create_registry(remote)
|
||||
params_list, params_dict = self.get_params(data_params, [])
|
||||
with remote.get_sudo(remote):
|
||||
for cmd in command:
|
||||
LOG.info(
|
||||
"Running command '{cmd}' on node {node}".format(
|
||||
cmd=cmd,
|
||||
node=remote.hostname
|
||||
)
|
||||
)
|
||||
result = remote.execute(cmd)
|
||||
assert result['exit_code'] == 0
|
||||
ccpcluster.do_build(remote, *params_list, **params_dict)
|
||||
post_install_k8s_checks.check_calico_network(remote, k8sclient)
|
||||
else:
|
||||
registry = settings.REGISTRY
|
||||
if not registry:
|
||||
if not settings.REGISTRY:
|
||||
raise ValueError("The REGISTRY variable should be set with "
|
||||
"external registry address, "
|
||||
"current value {0}".format(settings.REGISTRY))
|
||||
|
||||
exclude_list = ['build', '--builder-push', '--builder-workers 1']
|
||||
yaml_path = os.path.join(
|
||||
os.getcwd(),
|
||||
'/fuel_ccp_tests/templates/'
|
||||
'k8s_templates/build-deploy_cluster.yaml')
|
||||
|
||||
with open(yaml_path, 'r') as yaml_path:
|
||||
params_list = yaml.load(yaml_path)['ccp-microservices-options']
|
||||
params = self.get_params(params_list, exclude_list)
|
||||
data = ' '.join(params)
|
||||
data = data.format(
|
||||
registry_address=registry,
|
||||
images_namespace=settings.IMAGES_NAMESPACE,
|
||||
images_tag=settings.IMAGES_TAG)
|
||||
command = [
|
||||
'ccp {0}'.format(data),
|
||||
]
|
||||
exclude_list = ['builder-push', 'builder-workers']
|
||||
params_list, params_dict = self.get_params(data_params, exclude_list)
|
||||
with remote.get_sudo(remote):
|
||||
for cmd in command:
|
||||
LOG.info(
|
||||
"Running command '{cmd}' on node {node}".format(
|
||||
cmd=cmd,
|
||||
node=remote.hostname
|
||||
)
|
||||
)
|
||||
result = remote.execute(cmd)
|
||||
assert result['exit_code'] == 0
|
||||
ccpcluster.do_deploy(*params_list, **params_dict)
|
||||
post_os_deploy_checks.check_jobs_status(k8sclient, timeout=1500,
|
||||
namespace='ccp')
|
||||
post_os_deploy_checks.check_pods_status(k8sclient, timeout=1500,
|
||||
|
|
Loading…
Reference in New Issue