Skip to content

Commit

Permalink
pulp_pull: make pulls insecure
Browse files Browse the repository at this point in the history
  • Loading branch information
vrutkovs authored and lcarva committed Mar 6, 2017
1 parent ddb7423 commit abf4a81
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
5 changes: 3 additions & 2 deletions atomic_reactor/plugins/post_pulp_pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class PulpPullPlugin(PostBuildPlugin):
key = 'pulp_pull'
is_allowed_to_fail = False

def __init__(self, tasker, workflow, timeout=600, retry_delay=30):
def __init__(self, tasker, workflow, timeout=600, retry_delay=30, insecure=False):
"""
constructor
Expand All @@ -43,6 +43,7 @@ def __init__(self, tasker, workflow, timeout=600, retry_delay=30):
super(PulpPullPlugin, self).__init__(tasker, workflow)
self.timeout = timeout
self.retry_delay = retry_delay
self.insecure = insecure

def run(self):
start = time()
Expand All @@ -59,7 +60,7 @@ def run(self):

while True:
# Pull the image from Crane
name = self.tasker.pull_image(pullspec)
name = self.tasker.pull_image(pullspec, insecure=self.insecure)

# Inspect it
try:
Expand Down
32 changes: 17 additions & 15 deletions tests/plugins/test_pulp_pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from atomic_reactor.plugins.post_pulp_pull import (PulpPullPlugin,
CraneTimeoutError)
from atomic_reactor.inner import TagConf, PushConf
from atomic_reactor.util import ImageName
from docker.errors import NotFound
import time

from flexmock import flexmock
import pytest
Expand All @@ -20,7 +20,7 @@ class MockerTasker(object):
def __init__(self):
self.pulled_images = []

def pull_image(self, image):
def pull_image(self, image, insecure):
self.pulled_images.append(image)
return image.to_str()

Expand All @@ -31,6 +31,8 @@ def inspect_image(self, image):
class TestPostPulpPull(object):
TEST_UNIQUE_IMAGE = 'foo:unique-tag'
CRANE_URI = 'crane.example.com'
EXPECTED_IMAGE = ImageName.parse('%s/%s' % (CRANE_URI, TEST_UNIQUE_IMAGE))
EXPECTED_PULLSPEC = EXPECTED_IMAGE.to_str()

def workflow(self):
tag_conf = TagConf()
Expand All @@ -44,49 +46,50 @@ def workflow(self):
builder=builder,
plugin_workspace={})

def test_pull_first_time(self):
@pytest.mark.parametrize('insecure', [True, False])
def test_pull_first_time(self, insecure):
workflow = self.workflow()
tasker = MockerTasker()
expected_pullspec = '%s/%s' % (self.CRANE_URI, self.TEST_UNIQUE_IMAGE)

test_id = 'sha256:(new)'

(flexmock(tasker)
.should_call('pull_image')
.and_return(expected_pullspec)
.with_args(self.EXPECTED_IMAGE, insecure=insecure)
.and_return(self.EXPECTED_PULLSPEC)
.once()
.ordered())

(flexmock(tasker)
.should_receive('inspect_image')
.with_args(expected_pullspec)
.with_args(self.EXPECTED_PULLSPEC)
.and_return({'Id': test_id})
.once())

plugin = PulpPullPlugin(tasker, workflow)
plugin = PulpPullPlugin(tasker, workflow, insecure=insecure)

# Plugin return value is the new ID
assert plugin.run() == test_id

assert len(tasker.pulled_images) == 1
pulled = tasker.pulled_images[0].to_str()
assert pulled == expected_pullspec
assert pulled == self.EXPECTED_PULLSPEC

# Image ID is updated in workflow
assert workflow.builder.image_id == test_id

def test_pull_timeout(self):
workflow = self.workflow()
tasker = MockerTasker()
expected_pullspec = '%s/%s' % (self.CRANE_URI, self.TEST_UNIQUE_IMAGE)

(flexmock(tasker)
.should_call('pull_image')
.and_return(expected_pullspec)
.and_return(self.EXPECTED_PULLSPEC)
.times(3))

(flexmock(tasker)
.should_receive('inspect_image')
.with_args(expected_pullspec)
.with_args(self.EXPECTED_PULLSPEC)
.and_raise(NotFound('message', flexmock(content=None)))
.times(3))

Expand All @@ -99,17 +102,16 @@ def test_pull_timeout(self):
def test_pull_retry(self):
workflow = self.workflow()
tasker = MockerTasker()
expected_pullspec = '%s/%s' % (self.CRANE_URI, self.TEST_UNIQUE_IMAGE)
test_id = 'sha256:(new)'

(flexmock(tasker)
.should_call('pull_image')
.and_return(expected_pullspec)
.and_return(self.EXPECTED_PULLSPEC)
.times(3))

(flexmock(tasker)
.should_receive('inspect_image')
.with_args(expected_pullspec)
.with_args(self.EXPECTED_PULLSPEC)
.and_raise(NotFound('message', flexmock(content=None)))
.and_raise(NotFound('message', flexmock(content=None)))
.and_return({'Id': test_id})
Expand All @@ -123,7 +125,7 @@ def test_pull_retry(self):
assert len(tasker.pulled_images) == 3
for image in tasker.pulled_images:
pulled = image.to_str()
assert pulled == expected_pullspec
assert pulled == self.EXPECTED_PULLSPEC

# Image ID is updated in workflow
assert workflow.builder.image_id == test_id

0 comments on commit abf4a81

Please sign in to comment.