~jameinel/juju-core/scale-testing

« back to all changes in this revision

Viewing changes to worker/uniter/uniter_test.go

[r=dimitern],[bug=1067979] state;apiserver: Fix a race - lp bug #1067979

This introduces some changes to how charm store
charms are added through the API (in state and
to provider storage). Now PrepareStoreCharmUpload
is called before trying to download the charm,
repackage it and upload it to storage, in order
to reserve a charm URL in state with pending
state. Added a test that demonstrates multiple
concurrent deployments of the same charm does
not cause the race issues, like mentioned in
the bug.

A few drive-by fixes brought up during review:
* Added ReadSHA256 and ReadFileSHA256 helpers in
  utils, and changed most places where hashes
  are calculated to use them.
* Charms are now uploaded to storage with a
  randomly generated archive names with the
  format "<charm-name>-<revision>-<uuid>".
  This allows multiple concurrent uploads
  to happen safely, and at the end AddCharm
  in the API checks to see if the charm info
  is already updated in state and if so, deletes
  the duplicated upload.
* Added GetEnvironStorage helper to environs/testing.
* Fixed potential compatibility issues with older
  versions and the recently added PendingUpload
  and Placeholder fields of the charm document.

Also tested multiple concurrent deployments with
the local provider manually and updated the bug
accordingly.

https://codereview.appspot.com/53210044/

R=fwereade

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
import (
7
7
        "bytes"
8
 
        "crypto/sha256"
9
 
        "encoding/hex"
10
8
        "fmt"
11
 
        "io"
12
9
        "io/ioutil"
13
10
        "net/rpc"
14
11
        "net/url"
1199
1196
        err := s.dir.BundleTo(&buf)
1200
1197
        c.Assert(err, gc.IsNil)
1201
1198
        body := buf.Bytes()
1202
 
        hasher := sha256.New()
1203
 
        _, err = io.Copy(hasher, &buf)
 
1199
        hash, _, err := utils.ReadSHA256(&buf)
1204
1200
        c.Assert(err, gc.IsNil)
1205
 
        hash := hex.EncodeToString(hasher.Sum(nil))
1206
1201
        key := fmt.Sprintf("/charms/%s/%d", s.dir.Meta().Name, s.dir.Revision())
1207
1202
        hurl, err := url.Parse(coretesting.Server.URL + key)
1208
1203
        c.Assert(err, gc.IsNil)