~ubuntu-branches/ubuntu/trusty/juju-core/trusty-proposed

« back to all changes in this revision

Viewing changes to src/launchpad.net/juju-core/state/apiserver/client/client_test.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-01-29 11:40:20 UTC
  • mfrom: (23.1.1 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20140129114020-ejieitm8smtt5vln
Tags: 1.17.1-0ubuntu2
d/tests/local-provider: Don't fail tests if ~/.juju is present as its
created by the juju version command. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
        "fmt"
8
8
        "net/url"
9
9
        "strconv"
 
10
        "strings"
10
11
 
11
12
        gc "launchpad.net/gocheck"
12
13
 
13
14
        "launchpad.net/juju-core/charm"
 
15
        coreCloudinit "launchpad.net/juju-core/cloudinit"
 
16
        "launchpad.net/juju-core/cloudinit/sshinit"
14
17
        "launchpad.net/juju-core/constraints"
15
18
        "launchpad.net/juju-core/environs"
 
19
        "launchpad.net/juju-core/environs/cloudinit"
16
20
        "launchpad.net/juju-core/environs/config"
 
21
        envtools "launchpad.net/juju-core/environs/tools"
17
22
        "launchpad.net/juju-core/errors"
18
23
        "launchpad.net/juju-core/instance"
19
24
        "launchpad.net/juju-core/state"
20
25
        "launchpad.net/juju-core/state/api"
21
26
        "launchpad.net/juju-core/state/api/params"
22
27
        "launchpad.net/juju-core/state/apiserver/client"
 
28
        "launchpad.net/juju-core/state/statecmd"
23
29
        coretesting "launchpad.net/juju-core/testing"
24
30
        jc "launchpad.net/juju-core/testing/checkers"
25
 
        "launchpad.net/juju-core/tools"
 
31
        coretools "launchpad.net/juju-core/tools"
26
32
        "launchpad.net/juju-core/version"
27
33
)
28
34
 
1650
1656
 
1651
1657
func (s *clientSuite) TestMachineConfig(c *gc.C) {
1652
1658
        addrs := []instance.Address{instance.NewAddress("1.2.3.4")}
1653
 
        hc := instance.MustParseHardware("mem=4G")
 
1659
        hc := instance.MustParseHardware("mem=4G arch=amd64")
1654
1660
        apiParams := params.AddMachineParams{
1655
1661
                Jobs:       []params.MachineJob{params.JobHostUnits},
1656
1662
                InstanceId: instance.Id("1234"),
1663
1669
        c.Assert(len(machines), gc.Equals, 1)
1664
1670
 
1665
1671
        machineId := machines[0].Machine
1666
 
        machineConfig, err := s.APIState.Client().MachineConfig(machineId, config.DefaultSeries, "amd64")
 
1672
        machineConfig, err := s.APIState.Client().MachineConfig(machineId)
1667
1673
        c.Assert(err, gc.IsNil)
1668
1674
 
1669
1675
        envConfig, err := s.State.EnvironConfig()
1682
1688
        c.Assert(machineConfig.EnvironAttrs["name"], gc.Equals, "dummyenv")
1683
1689
}
1684
1690
 
 
1691
func (s *clientSuite) TestMachineConfigNoArch(c *gc.C) {
 
1692
        apiParams := params.AddMachineParams{
 
1693
                Jobs:       []params.MachineJob{params.JobHostUnits},
 
1694
                InstanceId: instance.Id("1234"),
 
1695
                Nonce:      "foo",
 
1696
        }
 
1697
        machines, err := s.APIState.Client().AddMachines([]params.AddMachineParams{apiParams})
 
1698
        c.Assert(err, gc.IsNil)
 
1699
        c.Assert(len(machines), gc.Equals, 1)
 
1700
        _, err = s.APIState.Client().MachineConfig(machines[0].Machine)
 
1701
        c.Assert(err, gc.ErrorMatches, fmt.Sprintf("arch is not set for %q", "machine-"+machines[0].Machine))
 
1702
}
 
1703
 
1685
1704
func (s *clientSuite) TestMachineConfigNoTools(c *gc.C) {
 
1705
        s.PatchValue(&envtools.DefaultBaseURL, "")
1686
1706
        addrs := []instance.Address{instance.NewAddress("1.2.3.4")}
1687
 
        hc := instance.MustParseHardware("mem=4G")
 
1707
        hc := instance.MustParseHardware("mem=4G arch=amd64")
1688
1708
        apiParams := params.AddMachineParams{
1689
1709
                Series:     "quantal",
1690
1710
                Jobs:       []params.MachineJob{params.JobHostUnits},
1695
1715
        }
1696
1716
        machines, err := s.APIState.Client().AddMachines([]params.AddMachineParams{apiParams})
1697
1717
        c.Assert(err, gc.IsNil)
1698
 
        _, err = s.APIState.Client().MachineConfig(machines[0].Machine, "quantal", "amd64")
1699
 
        c.Assert(err, gc.ErrorMatches, tools.ErrNoMatches.Error())
 
1718
        _, err = s.APIState.Client().MachineConfig(machines[0].Machine)
 
1719
        c.Assert(err, gc.ErrorMatches, coretools.ErrNoMatches.Error())
 
1720
}
 
1721
 
 
1722
func (s *clientSuite) TestProvisioningScript(c *gc.C) {
 
1723
        // Inject a machine and then call the ProvisioningScript API.
 
1724
        // The result should be the same as when calling MachineConfig,
 
1725
        // converting it to a cloudinit.MachineConfig, and disabling
 
1726
        // apt_upgrade.
 
1727
        apiParams := params.AddMachineParams{
 
1728
                Jobs:       []params.MachineJob{params.JobHostUnits},
 
1729
                InstanceId: instance.Id("1234"),
 
1730
                Nonce:      "foo",
 
1731
                HardwareCharacteristics: instance.MustParseHardware("arch=amd64"),
 
1732
        }
 
1733
        machines, err := s.APIState.Client().AddMachines([]params.AddMachineParams{apiParams})
 
1734
        c.Assert(err, gc.IsNil)
 
1735
        c.Assert(len(machines), gc.Equals, 1)
 
1736
        machineId := machines[0].Machine
 
1737
        machineConfig, err := s.APIState.Client().MachineConfig(machineId)
 
1738
        c.Assert(err, gc.IsNil)
 
1739
        // Call ProvisioningScript. Normally ProvisioningScript and
 
1740
        // MachineConfig are mutually exclusive; both of them will
 
1741
        // allocate a state/api password for the machine agent.
 
1742
        script, err := s.APIState.Client().ProvisioningScript(machineId, apiParams.Nonce)
 
1743
        c.Assert(err, gc.IsNil)
 
1744
        mcfg, err := statecmd.FinishMachineConfig(machineConfig, machineId, apiParams.Nonce, "")
 
1745
        c.Assert(err, gc.IsNil)
 
1746
        cloudcfg := coreCloudinit.New()
 
1747
        err = cloudinit.ConfigureJuju(mcfg, cloudcfg)
 
1748
        c.Assert(err, gc.IsNil)
 
1749
        cloudcfg.SetAptUpgrade(false)
 
1750
        sshinitScript, err := sshinit.ConfigureScript(cloudcfg)
 
1751
        c.Assert(err, gc.IsNil)
 
1752
        // ProvisioningScript internally calls MachineConfig,
 
1753
        // which allocates a new, random password. Everything
 
1754
        // about the scripts should be the same other than
 
1755
        // the line containing "oldpassword" from agent.conf.
 
1756
        scriptLines := strings.Split(script, "\n")
 
1757
        sshinitScriptLines := strings.Split(sshinitScript, "\n")
 
1758
        c.Assert(scriptLines, gc.HasLen, len(sshinitScriptLines))
 
1759
        for i, line := range scriptLines {
 
1760
                if strings.Contains(line, "oldpassword") {
 
1761
                        continue
 
1762
                }
 
1763
                c.Assert(line, gc.Equals, sshinitScriptLines[i])
 
1764
        }
1700
1765
}
1701
1766
 
1702
1767
func (s *clientSuite) TestClientAuthorizeStoreOnDeployServiceSetCharmAndAddCharm(c *gc.C) {