Skip to content

Commit

Permalink
getting the package ready for testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
earthmant committed Jan 22, 2015
1 parent 709bd0a commit 8a26380
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 38 deletions.
Empty file added .coveragerc
Empty file.
4 changes: 0 additions & 4 deletions .travis.yml
Expand Up @@ -11,7 +11,3 @@ install:
# - pip install coveralls
script:
- tox -e $TOX_ENV
# after_success:
# coveralls
notifications:
flowdock: 1f4ec6febcf1ac9b35ae6c1f0049471f
4 changes: 2 additions & 2 deletions docker_plugin/docker_client.py
Expand Up @@ -16,7 +16,7 @@
import docker

# Cloudify Imports
from Cloudify.exceptions import NonRecoverableError
from cloudify.exceptions import NonRecoverableError


def get_client(daemon_client):
Expand All @@ -33,7 +33,7 @@ def get_client(daemon_client):
"""

try:
return docker.Client(**daemon_client)
return docker.Client(base_url='unix://var/run/docker.sock')
except docker.errors.DockerException as e:
raise NonRecoverableError('Error while getting client: '
'{0}.'.format(str(e)))
12 changes: 6 additions & 6 deletions docker_plugin/tasks.py
Expand Up @@ -43,13 +43,13 @@ def pull(daemon_client=None, **_):
client = daemon_client or {}
client = get_client(daemon_client)

if ctx.node.properties['use_existing_resource'] is True:
if ctx.node.properties['use_external_resource'] is True:
ctx.instance.runtime_properties['repository'] = \
ctx.node.properties['resource_id']
return

arguments = dict()
args_to_merge = build_arg_dict(ctx.node.properties['params'].copy(), [])
args_to_merge = build_arg_dict(ctx.node.properties['params'].copy(), {})
arguments.update(args_to_merge)
arguments['repository'] = ctx.node.properties['resource_id']

Expand Down Expand Up @@ -85,7 +85,7 @@ def build(daemon_client=None, **_):
raise NonRecoverableError('No path to a Dockerfile was provided.')

arguments = dict()
args_to_merge = build_arg_dict(ctx.node.properties['params'].copy(), [])
args_to_merge = build_arg_dict(ctx.node.properties['params'].copy(), {})
arguments.update(args_to_merge)
arguments['path'] = ctx.node.properties['path']
arguments['fileobj'] = ctx.node.properties['fileobj']
Expand Down Expand Up @@ -119,7 +119,7 @@ def import_image(daemon_client=None, **_):
daemon_client = daemon_client or {}
client = get_client(daemon_client)
arguments = dict()
args_to_merge = build_arg_dict(ctx.node.properties['params'].copy(), [])
args_to_merge = build_arg_dict(ctx.node.properties['params'].copy(), {})
arguments.update(args_to_merge)
arguments['repository'] = ctx.node.properties['resource_id']
arguments['src'] = ctx.node.properties['src']
Expand All @@ -144,7 +144,7 @@ def create_container(daemon_client=None, **_):
client = get_client(daemon_client)

arguments = dict()
args_to_merge = build_arg_dict(ctx.node.properties['params'].copy(), [])
args_to_merge = build_arg_dict(ctx.node.properties['params'].copy(), {})
arguments.update(args_to_merge)
arguments['image'] = ctx.node.properties['resource_id']

Expand Down Expand Up @@ -174,7 +174,7 @@ def run(daemon_client=None, **_):
client = get_client(daemon_client)

arguments = dict()
args_to_merge = build_arg_dict(ctx.node.properties['params'].copy(), [])
args_to_merge = build_arg_dict(ctx.node.properties['params'].copy(), {})
arguments.update(args_to_merge)
arguments['container'] = \
ctx.instance.runtime_properties['docker_container']
Expand Down
21 changes: 17 additions & 4 deletions docker_plugin/tests/tests_pull.py
Expand Up @@ -17,14 +17,24 @@
import testtools

# Third Party Imports
from docker import Client
from docker import errors

# Cloudify Imports is imported and used in operations
from tasks import pull
from docker_plugin import tasks
from cloudify.mocks import MockCloudifyContext
from cloudify.exceptions import NonRecoverableError


class TestPull(testtools.TestCase):

def get_client(self):
try:
return Client(base_url='unix://var/run/docker.sock')
except errors.DockerException as e:
raise NonRecoverableError(
'Error while getting client: {0}.'.format(str(e)))

def mock_ctx(self, test_name):
""" Creates a mock context for the instance
tests
Expand All @@ -46,14 +56,17 @@ def mock_ctx(self, test_name):

return ctx

@testtools.skip
def test_pull_clean(self):
""" This test pulls the docker-dev image from
the docker hub and deletes it.
"""

ctx = self.mock_ctx('test_pull_clean')

client = self.get_client()

tasks.pull(ctx=ctx)
image_id = ctx.instance.runtime_properties['image_id']

if client.images(name=image_id) is not None:
test_passed = True
client.remove_image(image_id)
self.AssertTrue(test_passed)
22 changes: 4 additions & 18 deletions setup.py
Expand Up @@ -13,25 +13,12 @@
# under the License.


import os
import setuptools
from setuptools.command.install import install
from setuptools import setup

import docker_installation.apt_get_wrapper
# Replace the place holders with values for your project

setup(

class CustomInstallCommand(install):
def run(self):
docker_installation.apt_get_wrapper.install_docker()
install.run(self)


additional_configuration = {}
if 'CELERY_WORK_DIR' in os.environ:
additional_configuration.update(
{'cmdclass': {'install': CustomInstallCommand}})

setuptools.setup(
name='cloudify-docker-plugin',
version='1.2a3',
author='Gigaspaces',
Expand All @@ -41,9 +28,8 @@ def run(self):
license='LICENCE',
install_requires=[
'cloudify-plugins-common==3.2a3',
'docker-py==0.6.0',
'docker-py==0.7.1',
],
packages=['docker_plugin'],
zip_safe=False,
**additional_configuration
)
6 changes: 2 additions & 4 deletions tox.ini
Expand Up @@ -5,14 +5,12 @@ envlist=flake8,docs,py27
[testenv]
deps =
-rdev-requirements.txt
-rtest-requirements.txt

[testenv:py27]
deps =
nose
nose-cov
testfixtures
{[testenv]deps}
commands=nosetests --with-cov --cov docker_plugin docker_plugin/tests/unit_tests docker_plugin/tests/tests
commands=nosetests -v --with-cov --cov docker_plugin docker_plugin/tests

[testenv:docs]
changedir=docs
Expand Down

0 comments on commit 8a26380

Please sign in to comment.