Merge lp://qastaging/~cjohnston/ubuntu-ci-services-itself/get-swift-image into lp://qastaging/ubuntu-ci-services-itself

Proposed by Chris Johnston
Status: Merged
Approved by: Chris Johnston
Approved revision: 405
Merged at revision: 410
Proposed branch: lp://qastaging/~cjohnston/ubuntu-ci-services-itself/get-swift-image
Merge into: lp://qastaging/ubuntu-ci-services-itself
Diff against target: 442 lines (+300/-25)
6 files modified
ci-utils/ci_utils/data_store/__init__.py (+2/-2)
cli/ci_libs/image.py (+93/-0)
cli/ci_libs/ticket.py (+2/-1)
cli/ci_libs/utils.py (+6/-1)
cli/tests/test_image.py (+168/-0)
cli/ubuntu-ci (+29/-21)
To merge this branch: bzr merge lp://qastaging/~cjohnston/ubuntu-ci-services-itself/get-swift-image
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Chris Johnston (community) Needs Resubmitting
Andy Doan (community) Approve
Review via email: mp+211221@code.qastaging.launchpad.net

Commit message

Add the ability to get_image to the CLI

Description of the change

The CI Engine builds a release candidate image that includes all of the tested and 'approved' packages included in it.

Currently the built images are stored in glance and swift. The images stored in glance are not always available for users to download due to different provider policies. Because of this we had to start storing the images in swift. They are presently stored in a container called ticket-#-image (where # is the ticket number). This container is a private container to avoid the images being available without credentials (NOTE: we should probably make the public/private availability a choice either at deployment time or at ticket creation time).

Because the image containers are presently set to be private, even though the artifact reference can be seen on the WebUI, it isn't possible for a user to download the image via the WebUI since they are missing the proper credentials. Because of this, we needed a way for the user to be able to download the image with the proper credentials.

Also note that Ursula is working on some additional tests for this MP which will follow soon.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:404
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/440/
Executed test runs:

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/440/rebuild

review: Approve (continuous-integration)
Revision history for this message
Ursula Junque (ursinha) wrote :

+class GetTicketImage(TestCaseWithGnupg):

I changed this in my branch earlier today and I think it got lost in the tons of changes after that: these tests don't check anything gnupg related, so I think we can use unittest.TestCase here.

402. By Chris Johnston

Update per review - use unittest

Revision history for this message
Evan (ev) wrote :

> Because the image containers are presently set to be private, even though the
> artifact reference can be seen on the WebUI, it isn't possible for a user to
> download the image via the WebUI since they are missing the proper
> credentials. Because of this, we needed a way for the user to be able to
> download the image with the proper credentials.

Just to throw support behind this, I think it's entirely reasonable that we do not provide access to the images via the webui in phase 0 (and I think we discussed as much on IRC when planning where this feature would get implemented).

Once we're past phase 0, I want to see us put data store object creation behind a new intermediary service that manages the credentials. The CLI should just send the signed GPG content and this intermediary should validate the signature. No cloud credentials should change hands.

This is bug 1288710.

Revision history for this message
Andy Doan (doanac) wrote :

On 03/16/2014 06:33 PM, Chris Johnston wrote:
> +def get_image(args):
> + if args.ticket:
> + ticket = args.ticket
> + else:
> + ticket_status_base = utils.CI_URL + utils.TICKET_STATUS_BASE
> + url = ticket_status_base + '?current_workflow_step={}'.format(
> + ticket_states.TicketWorkflowStep.COMPLETED.value)
> + data = utils.get(url)

> + tickets = []
> + for o in data['objects']:
> + tickets.append(o[u'id'])
> + tickets = sorted(tickets, reverse=True)
> + ticket = tickets.pop(0)

You could do this in one line with:
   ticket = max([x['id'] for x in data['objects']])

If there are no completed tickets, does data['objects'] exist? Maybe to
make this super safe you do:
      ticket = max([x['id'] for x in data.get('objects', [])])

> +
> + data = _get_image_artifact(ticket)
> + ticket_id = str(ticket) + '-image'
> + ds = data_store.create_for_ticket(ticket_id=ticket_id,
> + auth_config=utils.AUTH_CONFIG,
> + public=False)
> + image = data['objects'][0][u'name']
> + local_path = os.path.join(utils.HOME, image)

I'm not a fan of this fixed download location. I'd want to specify via
the CLI and not have this throwing stuff under my $HOME. This might just
be me.

> + if os.path.exists(local_path):
> + print("{} already exists.".format(local_path))
> + else:
> + try:
> + download = ds.get_file(image)
> + fp = open(local_path, 'wb')
> + fp.write(download)

Is there a way we can have swift stream this to the file descriptor
rather than loading the ~200M into memory and writing it all to disk?

Revision history for this message
Francis Ginther (fginther) wrote :

The mechanics of this look good and I was able to test that it works (from a ticket I submitted earlier today). I would prefer that it drop the image into my current dir or support an option to specify the location.

If there are significant issues with addressing Andy's comments, then I would strongly consider approving this as it does fill a functionality gap.

Revision history for this message
Joe Talbott (joetalbott) wrote :

L60 I think the preferred syntax is; except Blah as b: rather than; except Blah, b:

L235 I prefer to name my test classes as TextXYZ so they stand out visually to me as tests.

I agree with @Andy regarding the download location and avoiding reading the entire file into memory.

Revision history for this message
Joe Talbott (joetalbott) wrote :

Hrm, after a bit of research, swiftclient.client.get_object doesn't support streaming. So the data-store will need to be adjusted to handle streaming perhaps by using the url and using http streaming. I'd say that's for a later MP.

403. By Chris Johnston

merge trunk

404. By Chris Johnston

Change the way to get the newest ticket per review

Revision history for this message
Andy Doan (doanac) wrote :

lets get this merged. and then fix the saving logic separately but soon.

review: Approve
405. By Chris Johnston

Require a user to specify where they would like to download their RC image to

Revision history for this message
Chris Johnston (cjohnston) wrote :

r404 changes how we get the 'latest' completed ticket
r405 changes to require the user to specify where they want to download their image to

review: Needs Resubmitting
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:405
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/448/
Executed test runs:

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/448/rebuild

review: Approve (continuous-integration)
Revision history for this message
Andy Doan (doanac) wrote :

looks good. we should just get this merged i think. one note:

246 + self.image_path = os.path.join(
247 + utils.HOME, 'd62d3d9a-ac3d-11e3-847d-fa163eaf5928.img')
248 + self.addCleanup(self._remove_image)

you could use tempfile for that now so the test doesn't mess with $HOME

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches