Skip to content

Commit

Permalink
VCDA-415: validate settings before creating template (vmware#65)
Browse files Browse the repository at this point in the history
- validates settings before creating template
- updated requirements version
- added format-code.sh script
- added travis support

Signed-off-by: Paco Gomez <contact@pacogomez.com>
  • Loading branch information
pacogomez authored Jan 26, 2018
1 parent 8ea9342 commit a7f0d49
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 52 deletions.
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language: python

python:
- '3.6'

install:
- pip install -r requirements.txt
- python setup.py install
- pip install tox

script:
- pip list --format=columns | grep container-service-extension
- python -c 'import pkg_resources; print(pkg_resources.require("pyvcloud")[0].version)'
- tox -e flake8
32 changes: 10 additions & 22 deletions container_service_extension/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,28 +104,16 @@

SAMPLE_CONFIG = {
'broker': {
'type':
'default',
'org':
'Admin',
'vdc':
'Catalog',
'catalog':
'cse',
'network':
'admin_network',
'ip_allocation_mode':
'pool',
'storage_profile':
'*',
'default_template':
SAMPLE_TEMPLATE_PHOTON_V2['name'],
'templates': [
SAMPLE_TEMPLATE_PHOTON_V2,
SAMPLE_TEMPLATE_UBUNTU_16_04
],
'cse_msg_dir':
'/tmp/cse'
'type': 'default',
'org': 'Admin',
'vdc': 'Catalog',
'catalog': 'cse',
'network': 'admin_network',
'ip_allocation_mode': 'pool',
'storage_profile': '*',
'default_template': SAMPLE_TEMPLATE_PHOTON_V2['name'],
'templates': [SAMPLE_TEMPLATE_PHOTON_V2, SAMPLE_TEMPLATE_UBUNTU_16_04],
'cse_msg_dir': '/tmp/cse'
}
}

Expand Down
27 changes: 16 additions & 11 deletions container_service_extension/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def get_config(config_file_name):
return config


def check_config(config_file_name, template='*'):
def check_config(config_file_name, template=None):
click.secho('Validating CSE on vCD from file: %s' % config_file_name)
if sys.version_info.major >= 3 and sys.version_info.minor >= 6:
python_valid = True
Expand Down Expand Up @@ -160,10 +160,6 @@ def check_config(config_file_name, template='*'):
'administrator (%s:%s): %s' % (config['vcd']['host'],
config['vcd']['port'],
bool_to_msg(True)))
click.secho('Validating \'%s\' service broker' % config['broker']['type'])
if config['broker']['type'] == 'default':
validate_broker_config_content(config, client, template)

platform = Platform(client)
for vc in platform.list_vcenters():
found = False
Expand All @@ -187,11 +183,20 @@ def check_config(config_file_name, template='*'):
vsphere_url.hostname, vsphere_url.port,
bool_to_msg(True)))

if template is None:
pass
else:
click.secho(
'Validating \'%s\' service broker' % config['broker']['type'])
if config['broker']['type'] == 'default':
validate_broker_config_content(config, client, template)

return config


def install_cse(ctx, config_file_name, template_name, no_capture, update,
amqp_install, ext_install):
check_config(config_file_name)
click.secho('Installing CSE on vCD from file: %s, template: %s' %
(config_file_name, template_name))
config = get_config(config_file_name)
Expand Down Expand Up @@ -242,8 +247,7 @@ def install_cse(ctx, config_file_name, template_name, no_capture, update,
k8s_template = None
try:
k8s_template = org.get_catalog_item(
config['broker']['catalog'],
template['catalog_item'])
config['broker']['catalog'], template['catalog_item'])
click.echo('Find template \'%s\', \'%s\': %s' %
(config['broker']['catalog'],
template['catalog_item'],
Expand All @@ -259,7 +263,8 @@ def install_cse(ctx, config_file_name, template_name, no_capture, update,
create_template(ctx, config, client, org, vdc_resource,
catalog, no_capture, template)
k8s_template = org.get_catalog_item(
config['broker']['catalog'], template['catalog_item'])
config['broker']['catalog'],
template['catalog_item'])
if update:
click.echo('Updated template \'%s\', \'%s\': %s' %
(config['broker']['catalog'],
Expand All @@ -273,9 +278,9 @@ def install_cse(ctx, config_file_name, template_name, no_capture, update,
except Exception:
LOGGER.error(traceback.format_exc())
click.echo('Can\'t create or update template \'%s\' '
'\'%s\': %s' % (template['name'],
config['broker']['catalog'],
template['catalog_item']))
'\'%s\': %s' %
(template['name'], config['broker']['catalog'],
template['catalog_item']))
configure_amqp_settings(ctx, client, config, amqp_install)
register_extension(ctx, client, config, ext_install)
click.secho('Start CSE with: \'cse run %s\'' % config_file_name)
Expand Down
5 changes: 2 additions & 3 deletions container_service_extension/cse.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import click
from vcd_cli.utils import stdout
from vcd_cli.vcd import abort_if_false

from container_service_extension.config import check_config
from container_service_extension.config import generate_sample_config
Expand Down Expand Up @@ -164,8 +163,8 @@ def check(ctx, config, template):
default='prompt',
type=click.Choice(['prompt', 'skip', 'config']),
help='API Extension configuration')
def install(ctx, config, template, update,
no_capture, amqp_install, ext_install):
def install(ctx, config, template, update, no_capture, amqp_install,
ext_install):
"""Install CSE on vCloud Director."""
try:
install_cse(ctx, config, template, no_capture, update, amqp_install,
Expand Down
8 changes: 8 additions & 0 deletions format-code.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

yapf -i container_service_extension/*.py
yapf -i container_service_extension/client/*.py
yapf -i tests/*.py
flake8 container_service_extension/*.py
flake8 container_service_extension/client/*.py
flake8 tests/*.py
10 changes: 5 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cachetools
humanfriendly
pika >= 0.10.0
cachetools >= 2.0.1
humanfriendly >= 4.8
pika >= 0.11.2
pyvcloud >= 19.1.1
vcd-cli >= 20.1.1
vsphere-guest-run >= 0.0.3
pyvcloud >= 19.1.1.dev16
vcd-cli >= 20.1.1.dev11
2 changes: 0 additions & 2 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@ flake8
flake8-import-order
flake8_docstrings
hacking
nose>=1.3.6
nose-testconfig>=0.9.1
yapf
11 changes: 2 additions & 9 deletions tests/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@
# Copyright (c) 2017 VMware, Inc. All Rights Reserved.
# SPDX-License-Identifier: BSD-2-Clause

import os
import unittest
import yaml
from pyvcloud.vcd.client import Client

from pyvcloud.vcd.client import TaskStatus
from pyvcloud.vcd.test import TestCase


from container_service_extension.client.cluster import Cluster

class TestCluster(TestCase):

class TestCluster(TestCase):
def test_01_template_list(self):
logged_in_org = self.client.get_org()
assert self.config['vcd']['org'] == logged_in_org.get('name')
Expand Down Expand Up @@ -56,9 +53,5 @@ def test_05_cluster_list(self):
assert len(clusters) == 0






if __name__ == '__main__':
unittest.main()

0 comments on commit a7f0d49

Please sign in to comment.