Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
8e8285b
some changes on readme
ricardoalcocer Sep 20, 2016
7626d60
small change on readme
ricardoalcocer Sep 20, 2016
283199c
added header
ricardoalcocer Sep 20, 2016
529e978
added title
ricardoalcocer Sep 20, 2016
93616e3
attempt at fixing links
ricardoalcocer Sep 20, 2016
8e70a5d
attempt at fixing links
ricardoalcocer Sep 20, 2016
2fa1a3c
attempt at fixing links
ricardoalcocer Sep 20, 2016
5ba9766
added section
ricardoalcocer Sep 20, 2016
2d5e508
added link
ricardoalcocer Sep 20, 2016
944dfc0
readability improvements
ricardoalcocer Sep 29, 2016
dc401f7
removed changelog area
ricardoalcocer Sep 29, 2016
b1a31fc
fixed typo
ricardoalcocer Sep 29, 2016
accb418
Merge pull request #89 from QualiSystems/borismod_add_l1
borismod Oct 10, 2016
ffe69ff
Merge branch 'master' into alco-readme
borismod Oct 20, 2016
8468217
add tosca templates
borismod Nov 6, 2016
74ac197
Merge pull request #95 from QualiSystems/update_templates
borismod Nov 6, 2016
6543036
Merge branch 'master' into alco-readme
borismod Nov 7, 2016
3cc4e9d
Merge pull request #90 from ricardoalcocer/alco-readme
borismod Nov 7, 2016
e4027a4
update readme for merging into master
borismod Nov 7, 2016
8fd1970
Merge pull request #97 from QualiSystems/update_readme
borismod Nov 7, 2016
d55a948
updating templates.yml with new templates for traffic-generators (#127)
johnathanvidu Dec 28, 2016
7f6cb76
duplicating templates yml
johnathanvidu Jan 15, 2017
78e09d4
updated templates 0.2.0 yml with the new definitions
johnathanvidu Jan 15, 2017
a30da85
Merge pull request #130 from QualiSystems/new_templates_yml_from_master
johnathanvidu Jan 15, 2017
614b43d
added minimum cloudshell version to templates_0.2.0.yml
johnathanvidu Jan 16, 2017
6ef9b4a
Merge pull request #132 from QualiSystems/add_cs_ver_to_templates_#128
johnathanvidu Jan 16, 2017
0becef3
Revert "added traffic generator template"
menib Dec 28, 2016
eb24cdb
added new template
menib Jan 30, 2017
a2e7450
Merge pull request #138 from QualiSystems/adding-firewall-template
johnathanvidu Jan 30, 2017
552e283
Merge remote-tracking branch 'origin/develop'
johnathanvidu Mar 8, 2017
4eacd67
update gitignore - ignore venv
johnathanvidu Mar 9, 2017
68544a1
Merge pull request #145 from QualiSystems/fixing_git_ignore
johnathanvidu Mar 9, 2017
bdc6d08
Update .travis.yml
johnathanvidu Mar 9, 2017
4bc24ad
fixing show command - failed to filter templates correctly and as a r…
johnathanvidu Mar 9, 2017
54062a6
Bump version: 0.2.4 → 0.2.5
johnathanvidu Mar 9, 2017
5444c07
Merge pull request #146 from QualiSystems/fixing_show_command
johnathanvidu Mar 9, 2017
81c4e18
fixed an error message in show command
johnathanvidu Mar 14, 2017
c47b3e3
fixed an issue regarding the error message when login failed for 2nd …
johnathanvidu Mar 14, 2017
8f38b51
Bump version: 0.2.5 → 0.2.6
johnathanvidu Mar 14, 2017
e4b71d7
Merge pull request #151 from QualiSystems/fixing_messages_bugs
johnathanvidu Mar 14, 2017
b21bba9
Merge branch 'master' into pack-categories-folder
kalsky Mar 17, 2017
7543486
Added support for categories.xml file
kalsky Mar 17, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ __pycache__/
# Distribution / packaging
.Python
env/
venv/
build/
develop-eggs/
dist/
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ deploy:
password:
secure: SAiYCl0mdmluytjsKmizaKk/10EN3VT3WcweOeJ3QPwu1o1scJ1gmQBggK68UwqQZjZgr6gcjvpoHKyjtDrg8VQuuQ5KKPt5Mldyw5LvyYHuwsN8dpJ7NYysplNOYb2RR0Fua4I12r0NvctUwJRQ1TEgJmBzWLuQ3aIcMVjltG5GDpBEr/6XnHzVu+ksvJ1iCmehgyPHLor2DFVFQ1va2iF3FVAgFwJA+LaW0QMrTI+NCGI/KFCJGkTQjhnpb7KjLG+ThyBCVLL6N4eR/koxGZA4Q8lcbMjsZHF+gjendWXW2frsJftGKoO89aEYi+nhdRjA4IMWZ7iISdXl/A3V4msoVHUXjacSiPQb2pBKlVva7dLDAZTK2nJQcFsvxED+V3vR0LO3FlbQLTl9nmbu75zh8fpQ9jnUhtyAc31Yd/R2bBUv/yymCEurBKzD9ucTxJvXOXFUVbOLcO1X+ODEKIRrKmTEJ7Jwy/3uF3gzOi5WVFcPxHTtIDKNM4ZfWgsxSOzoYfCNB8QEhkcYtIiL7WwzbctuQWFbEnquVsyPN9h/gEiGyggCrJEgfZw1RreSePx6MEsWS47+jl5SecKPX1xtKr9CpHkvPxbWLBSvbPns0TGnqXnIzci8yVLTJnBU39Zpcb2Z1xuflFTmTe1mOEXSFfY0TFVjpDAoSOvjGc4=
on:
branch: develop
branch: master
condition: $TRAVIS_PYTHON_VERSION = "2.7"
- provider: pypi
distribution: "sdist bdist_wheel"
Expand Down
5 changes: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
History
=======

0.2.6 (2017-03-14)
------------------

* Fixed some minor bugs

0.2.2 (2017-01-22)
------------------

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.2.4
current_version = 0.2.6
commit = True
tag = False

Expand Down
12 changes: 9 additions & 3 deletions shellfoundry/commands/install_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@ def install(self):
click.secho('Successfully installed shell', fg='green')

def _install_old_school_shell(self):
error = None
try:
cloudshell_config = self.cloudshell_config_reader.read()
shell_config = self.shell_config_reader.read()
self.installer.install(shell_config.name, cloudshell_config)
except HTTPError:
raise FatalError(u'Login to CloudShell failed. Please verify the credentials in the config')
except HTTPError as e:
if e.code == 401:
raise FatalError(u'Login to CloudShell failed. Please verify the credentials in the config')
error = e.msg
except URLError:
raise FatalError(u'Connection to CloudShell Server failed. Please make sure it is up and running properly.')
except Exception as e:
raise FatalError(u"Failed to install shell. CloudShell responded with: '{}'".format(e.message))
error = e.message

if error:
raise FatalError(u"Failed to install shell. CloudShell responded with: '{}'".format(error))
9 changes: 6 additions & 3 deletions shellfoundry/commands/show_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import requests
import shellfoundry.exceptions as exc

from shellfoundry.utilities import GEN_TWO_FILTER
from shellfoundry.utilities.template_retriever import TemplateRetriever, FilteredTemplateRetriever
from shellfoundry.utilities.template_versions import TemplateVersions

Expand All @@ -11,13 +12,15 @@

class ShowCommandExecutor(object):
def __init__(self, template_retriever=None):
self.template_retriever = template_retriever or FilteredTemplateRetriever('tosca', TemplateRetriever())
self.template_retriever = template_retriever or FilteredTemplateRetriever(GEN_TWO_FILTER, TemplateRetriever())

def show(self, template_name):
try:
template_repo = self.template_retriever.get_templates()[template_name].repository
except:
raise click.ClickException('Template does not exist')
raise click.ClickException(
"The template '{}' does not exist, please specify a valid 2nd Gen shell template.".format(
template_name))

if not template_repo:
raise click.ClickException('Repository url is empty')
Expand All @@ -27,7 +30,7 @@ def show(self, template_name):
except (requests.RequestException, exc.NoVersionsHaveBeenFoundException) as ex:
raise click.ClickException(ex.message)
branches.remove(MASTER_BRANCH_NAME)
if not TemplateVersions.has_versions(branches): # validating that besides master there are other versions
if not TemplateVersions.has_versions(branches): # validating that besides master there are other versions
raise click.ClickException("No versions have been found for this template")
self.mark_latest(branches)
for branch_name in branches:
Expand Down
3 changes: 2 additions & 1 deletion shellfoundry/utilities/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ def __init__(self, template_type=None):
NO_FILTER: NoFilter}

def filter(self, template_name):
return self.filters[self.template_type]().filter(template_name)
return self.filters.get(self.template_type, NoFilter)().filter(template_name)


class GenOneFilter(object):
def filter(self, template_name):
Expand Down
8 changes: 8 additions & 0 deletions shellfoundry/utilities/package_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def build_package(self, path, package_name, driver_name):
package_path = os.path.join(path, 'package')
self._copy_metadata(package_path, path)
self._copy_datamodel(package_path, path)
self._copy_categories(package_path, path)
self._copy_images(package_path, path)
self._copy_shellconfig(package_path, path)
self._create_driver(package_path, path, driver_name)
Expand Down Expand Up @@ -91,6 +92,13 @@ def _copy_shellconfig(package_path, path):
dest_dir_path = os.path.join(package_path, 'Configuration')
PackageBuilder._copy_file(dest_dir_path, src_file_path)

@staticmethod
def _copy_categories(package_path, path):
src_file_path = os.path.join(path, 'categories', 'categories.xml')
if os.path.exists(src_file_path):
dest_dir_path = os.path.join(package_path, 'Categories')
PackageBuilder._copy_file(dest_dir_path, src_file_path)

def _create_driver(self, package_path, path, driver_name):
dir_to_zip = os.path.join(path, 'src')
drivermetadata_path = os.path.join(dir_to_zip, 'drivermetadata.xml')
Expand Down
12 changes: 10 additions & 2 deletions shellfoundry/utilities/shell_package_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import click
import time

from urllib2 import HTTPError

from shellfoundry.exceptions import FatalError
from shellfoundry.utilities.config_reader import Configuration, CloudShellConfigReader
from shellfoundry.utilities.shell_package import ShellPackage
Expand Down Expand Up @@ -29,7 +31,10 @@ def install(self, path):
show_eta=False,
label=cs_connection_label
) as pbar:
client = self._open_connection_to_quali_server(cloudshell_config, pbar, retry=CloudShell_Max_Retries)
try:
client = self._open_connection_to_quali_server(cloudshell_config, pbar, retry=CloudShell_Max_Retries)
finally:
self._render_pbar_finish(pbar)

pbar_install_shell_len = 2 # amount of possible actions (update and add)
installation_label = 'Installing shell into CloudShell'.ljust(len(cs_connection_label))
Expand Down Expand Up @@ -57,8 +62,11 @@ def _open_connection_to_quali_server(self, cloudshell_config, pbar, retry):
port=cloudshell_config.port,
domain=cloudshell_config.domain,
password=cloudshell_config.password)
self._render_pbar_finish(pbar)
return client
except HTTPError as e:
if e.code == 401:
raise FatalError(u'Login to CloudShell failed. Please verify the credentials in the config')
raise FatalError('Connection to CloudShell Server failed. Please make sure it is up and running properly.')
except:
self._increase_pbar(pbar, time_wait=CloudShell_Retry_Interval_Sec)
return self._open_connection_to_quali_server(cloudshell_config, pbar, retry - 1)
Expand Down
2 changes: 1 addition & 1 deletion shellfoundry/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = '0.2.4'
__version__ = '0.2.6'

29 changes: 28 additions & 1 deletion tests/test_commands/test_install_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_proper_error_message_displayed_when_login_failed(self):
""")
os.chdir('nut_shell')
mock_installer = Mock()
mock_installer.install = Mock(side_effect=HTTPError('', '', LOGIN_ERROR_MESSAGE, None, None))
mock_installer.install = Mock(side_effect=HTTPError('', 401, LOGIN_ERROR_MESSAGE, None, None))
command_executor = InstallCommandExecutor(installer=mock_installer)

# Act
Expand All @@ -89,6 +89,33 @@ def test_proper_error_message_displayed_when_login_failed(self):
# Assert
self.assertTrue(context.exception, u'Login to CloudShell failed. Please verify the credentials in the config')

def test_proper_error_message_when_non_authentication_http_error_raised(self):
# Arrange
self.fs.CreateFile('nut_shell/shell.yml', contents="""
shell:
name: nut_shell
""")
self.fs.CreateFile('nut_shell/cloudshell_config.yml', contents="""
install:
host: localhost
port: 9000
username: YOUR_USERNAME
password: YOUR_PASSWORD
domain: Global
""")
os.chdir('nut_shell')
mock_installer = Mock()
mock_installer.install = Mock(side_effect=HTTPError('', 404, LOGIN_ERROR_MESSAGE, None, None))
command_executor = InstallCommandExecutor(installer=mock_installer)

# Act
with self.assertRaises(FatalError) as context:
command_executor.install()

# Assert
self.assertTrue(context.exception, u"Failed to install shell. CloudShell responded with: '{}'".format(
'Login to CloudShell failed. Please verify the credentials in the config'))

def test_proper_error_appears_when_connection_to_cs_failed(self):
# Arrange
self.fs.CreateFile('nut_shell/shell.yml', contents="""
Expand Down
7 changes: 4 additions & 3 deletions tests/test_commands/test_show_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ def test_show_template_shows_fail_message_when_template_does_not_exist(self):
ShowCommandExecutor(template_retriever_mock).show(template_name)

# Assert
self.assertTrue('Template does not exist' in context.exception)
self.assertTrue("The template '{}' does not exist, please specify a valid 2nd Gen shell template.".format(
template_name) in context.exception)

def test_repository_url_is_empty_raises_error(self):
# Arrange
Expand Down Expand Up @@ -118,8 +119,8 @@ def test_show_command_versions_request_failed_raises_error(self):
# Act
with patch('shellfoundry.commands.show_command.requests.get') as get_response_mock, \
self.assertRaises(click.ClickException) as context:
type(get_response_mock.return_value).status_code = PropertyMock(return_value=400)
ShowCommandExecutor(template_retriever_mock).show(template_name)
type(get_response_mock.return_value).status_code = PropertyMock(return_value=400)
ShowCommandExecutor(template_retriever_mock).show(template_name)

# Assert
self.assertTrue('Failed to receive versions from host' in context.exception)
Expand Down
40 changes: 40 additions & 0 deletions tests/test_utilities/test_package_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,46 @@ def test_pack_succeeds_when_shellconfig_is_missing(self):
assertFileExists(self, 'aws/amazon_web_services/package/DataModel/datamodel.xml')
assertFileExists(self, 'aws/amazon_web_services/package/Resource Drivers - Python/AwsDriver.zip')

def test_pack_succeeds_when_categories_file_is_missing(self):
# Arrange
self.fs.CreateFile('work/aws/amazon_web_services/datamodel/metadata.xml', contents='')
self.fs.CreateFile('work/aws/amazon_web_services/datamodel/datamodel.xml', contents='')
self.fs.CreateFile('work/aws/amazon_web_services/src/driver.py', contents='')
os.chdir('work')
builder = PackageBuilder()

# Act
with patch('click.echo'):
builder.build_package('aws/amazon_web_services', 'aws', 'AwsDriver')

# Assert
assertFileExists(self, 'aws/amazon_web_services/dist/aws.zip')
TestPackageBuilder.unzip('aws/amazon_web_services/dist/aws.zip', 'aws/amazon_web_services/package')
assertFileExists(self, 'aws/amazon_web_services/package/metadata.xml')
assertFileExists(self, 'aws/amazon_web_services/package/DataModel/datamodel.xml')
assertFileExists(self, 'aws/amazon_web_services/package/Resource Drivers - Python/AwsDriver.zip')

def test_pack_succeeds_when_categories_file_exists(self):
# Arrange
self.fs.CreateFile('work/aws/amazon_web_services/datamodel/metadata.xml', contents='')
self.fs.CreateFile('work/aws/amazon_web_services/datamodel/datamodel.xml', contents='')
self.fs.CreateFile('work/aws/amazon_web_services/categories/categories.xml', contents='')
self.fs.CreateFile('work/aws/amazon_web_services/src/driver.py', contents='')
os.chdir('work')
builder = PackageBuilder()

# Act
with patch('click.echo'):
builder.build_package('aws/amazon_web_services', 'aws', 'AwsDriver')

# Assert
assertFileExists(self, 'aws/amazon_web_services/dist/aws.zip')
TestPackageBuilder.unzip('aws/amazon_web_services/dist/aws.zip', 'aws/amazon_web_services/package')
assertFileExists(self, 'aws/amazon_web_services/package/metadata.xml')
assertFileExists(self, 'aws/amazon_web_services/package/DataModel/datamodel.xml')
assertFileExists(self, 'aws/amazon_web_services/package/Categories/categories.xml')
assertFileExists(self, 'aws/amazon_web_services/package/Resource Drivers - Python/AwsDriver.zip')

def test_it_replaces_wildcard_according_to_versioning_policy(self):
self.fs.CreateFile('work/aws/amazon_web_services/datamodel/metadata.xml', contents='')
self.fs.CreateFile('work/aws/amazon_web_services/datamodel/datamodel.xml', contents='')
Expand Down
29 changes: 29 additions & 0 deletions tests/test_utilities/test_shell_package_installer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import shellfoundry.utilities.shell_package_installer as spi

from urllib2 import HTTPError
from cloudshell.rest.exceptions import ShellNotFoundException
from mock import patch, Mock
from pyfakefs import fake_filesystem_unittest
Expand Down Expand Up @@ -89,6 +90,34 @@ def test_fail_to_open_connection_to_cs(self):
self.assertTrue(
context.exception.message == 'Connection to CloudShell Server failed. Please make sure it is up and running properly.')

@patch('shellfoundry.utilities.shell_package_installer.PackagingRestApiClient',
new=Mock(side_effect=HTTPError('', 401, '', None, None)))
def test_fail_to_login_into_cs(self):
# Arrange
spi.CloudShell_Retry_Interval_Sec = 0 # doing that for test to run faster with no sleeps between connection failures
installer = ShellPackageInstaller()

with self.assertRaises(FatalError) as context:
installer.install('work/nut-shell')

# Assert
self.assertTrue(
context.exception.message == u'Login to CloudShell failed. Please verify the credentials in the config')

@patch('shellfoundry.utilities.shell_package_installer.PackagingRestApiClient',
new=Mock(side_effect=HTTPError('', 403, '', None, None)))
def test_fail_with_http_error_other_than_authentication_error(self):
# Arrange
spi.CloudShell_Retry_Interval_Sec = 0 # doing that for test to run faster with no sleeps between connection failures
installer = ShellPackageInstaller()

with self.assertRaises(FatalError) as context:
installer.install('work/nut-shell')

# Assert
self.assertTrue(
context.exception.message == 'Connection to CloudShell Server failed. Please make sure it is up and running properly.')

@patch('shellfoundry.utilities.shell_package_installer.PackagingRestApiClient', new=Mock(
return_value=mock_rest_client(update_side_effect=ShellNotFoundException(),
add_side_effect=Exception(add_shell_error_message('Failed to add shell')))))
Expand Down