Exemple #1
0
func (s *instanceSuite) SetUpTest(c *gc.C) {
	s.BaseSuite.SetUpTest(c)

	cli, err := gosigma.NewClient(mock.Endpoint(""), mock.TestUser, mock.TestPassword, nil)
	c.Assert(err, gc.IsNil)

	mock.ResetServers()

	ds, err := data.ReadServer(strings.NewReader(jsonInstanceData))
	c.Assert(err, gc.IsNil)
	mock.AddServer(ds)

	mock.AddServer(&data.Server{
		Resource: data.Resource{URI: "uri", UUID: "uuid-no-ip"},
	})

	server, err := cli.Server("f4ec5097-121e-44a7-a207-75bc02163260")
	c.Assert(err, gc.IsNil)
	c.Assert(server, gc.NotNil)
	s.inst = &sigmaInstance{server}

	server, err = cli.Server("uuid-no-ip")
	c.Assert(err, gc.IsNil)
	c.Assert(server, gc.NotNil)
	s.instWithoutIP = &sigmaInstance{server}
}
Exemple #2
0
func (s *clientSuite) TestClientInstances(c *gc.C) {
	addTestClientServer(c, "", "")
	addTestClientServer(c, jujuMetaInstanceServer, "alien")
	addTestClientServer(c, jujuMetaInstanceStateServer, "alien")
	addTestClientServer(c, jujuMetaInstanceServer, "f54aac3a-9dcd-4a0c-86b5-24091478478c")
	addTestClientServer(c, jujuMetaInstanceServer, "f54aac3a-9dcd-4a0c-86b5-24091478478c")
	suuid := addTestClientServer(c, jujuMetaInstanceStateServer, "f54aac3a-9dcd-4a0c-86b5-24091478478c")

	cli, err := testNewClient(c, mock.Endpoint(""), mock.TestUser, mock.TestPassword)
	c.Assert(err, gc.IsNil)

	ss, err := cli.instances()
	c.Assert(err, gc.IsNil)
	c.Assert(ss, gc.NotNil)
	c.Check(ss, gc.HasLen, 3)

	sm, err := cli.instanceMap()
	c.Assert(err, gc.IsNil)
	c.Assert(sm, gc.NotNil)
	c.Check(sm, gc.HasLen, 3)

	ids, err := cli.getStateServerIds()
	c.Check(err, gc.IsNil)
	c.Check(len(ids), gc.Equals, 1)
	c.Check(string(ids[0]), gc.Equals, suuid)
}
Exemple #3
0
func (s *clientSuite) TestClientNewInstanceInvalidTemplate(c *gc.C) {
	cli, err := testNewClient(c, mock.Endpoint(""), mock.TestUser, mock.TestPassword)
	c.Assert(err, gc.IsNil)

	params := environs.StartInstanceParams{
		Constraints: constraints.Value{},
		InstanceConfig: &instancecfg.InstanceConfig{
			Bootstrap: true,
		},
	}
	err = params.InstanceConfig.SetTools(tools.List{
		&tools.Tools{
			Version: version.Binary{
				Series: "trusty",
			},
			URL: "https://0.1.2.3:2000/x.y.z.tgz",
		},
	})
	c.Assert(err, jc.ErrorIsNil)
	img := &imagemetadata.ImageMetadata{
		Id: "invalid-id",
	}
	server, drive, arch, err := cli.newInstance(params, img, nil)
	c.Check(server, gc.IsNil)
	c.Check(arch, gc.Equals, "")
	c.Check(drive, gc.IsNil)
	c.Check(err, gc.ErrorMatches, "Failed to query drive template: 404 Not Found, notexist, notfound")
}
Exemple #4
0
func (s *clientSuite) TestClientInvalidStopInstance(c *gc.C) {
	cli, err := testNewClient(c, mock.Endpoint(""), mock.TestUser, mock.TestPassword)
	c.Assert(err, gc.IsNil)

	var id instance.Id
	err = cli.stopInstance(id)
	c.Check(err, gc.ErrorMatches, "invalid instance id")

	err = cli.stopInstance("1234")
	c.Check(err, gc.ErrorMatches, "404 Not Found.*")
}
func (s *environInstanceSuite) SetUpSuite(c *gc.C) {
	s.BaseSuite.SetUpSuite(c)

	mock.Start()

	attrs := testing.Attrs{
		"name":     "testname",
		"uuid":     "f54aac3a-9dcd-4a0c-86b5-24091478478c",
		"region":   mock.Endpoint(""),
		"username": mock.TestUser,
		"password": mock.TestPassword,
	}
	s.baseConfig = newConfig(c, validAttrs().Merge(attrs))
}
Exemple #6
0
func (s *environInstanceSuite) SetUpSuite(c *gc.C) {
	s.BaseSuite.SetUpSuite(c)

	mock.Start()

	s.cloud = fakeCloudSpec()
	s.cloud.Endpoint = mock.Endpoint("")

	attrs := testing.Attrs{
		"name": "testname",
		"uuid": "f54aac3a-9dcd-4a0c-86b5-24091478478c",
	}
	s.baseConfig = newConfig(c, validAttrs().Merge(attrs))
}
Exemple #7
0
func (s *clientSuite) TestClientNewInstance(c *gc.C) {
	cli, err := testNewClient(c, mock.Endpoint(""), mock.TestUser, mock.TestPassword)
	c.Assert(err, gc.IsNil)

	cli.conn.OperationTimeout(1 * time.Second)

	params := environs.StartInstanceParams{
		Constraints: constraints.Value{},
		InstanceConfig: &instancecfg.InstanceConfig{
			Bootstrap: true,
		},
	}
	err = params.InstanceConfig.SetTools(tools.List{
		&tools.Tools{
			Version: version.Binary{
				Series: "trusty",
			},
			URL: "https://0.1.2.3:2000/x.y.z.tgz",
		},
	})
	c.Assert(err, jc.ErrorIsNil)
	img := &imagemetadata.ImageMetadata{
		Id: validImageId,
	}
	cs := newConstraints(params.InstanceConfig.Bootstrap, params.Constraints, img)
	c.Assert(cs, gc.NotNil)
	c.Check(err, gc.IsNil)

	templateDrive := &data.Drive{
		Resource: data.Resource{URI: "uri", UUID: cs.driveTemplate},
		LibraryDrive: data.LibraryDrive{
			Arch:      "64",
			ImageType: "image-type",
			OS:        "os",
			Paid:      true,
		},
		Size:   2200 * gosigma.Megabyte,
		Status: "unmounted",
	}
	mock.ResetDrives()
	mock.LibDrives.Add(templateDrive)

	server, drive, arch, err := cli.newInstance(params, img, utils.Gzip([]byte{}))
	c.Check(server, gc.NotNil)
	c.Check(drive, gc.NotNil)
	c.Check(arch, gc.NotNil)
	c.Check(err, gc.IsNil)
}
Exemple #8
0
func (s *clientSuite) TestClientNewInstanceInvalidParams(c *gc.C) {
	cli, err := testNewClient(c, mock.Endpoint(""), mock.TestUser, mock.TestPassword)
	c.Assert(err, gc.IsNil)

	params := environs.StartInstanceParams{
		Constraints: constraints.Value{},
	}
	img := &imagemetadata.ImageMetadata{
		Id: validImageId,
	}
	server, drive, arch, err := cli.newInstance(params, img, nil)
	c.Check(server, gc.IsNil)
	c.Check(arch, gc.Equals, "")
	c.Check(drive, gc.IsNil)
	c.Check(err, gc.ErrorMatches, "invalid configuration for new instance: InstanceConfig is nil")
}
Exemple #9
0
func (s *clientSuite) TestClientStopStateInstance(c *gc.C) {
	addTestClientServer(c, "", "")

	addTestClientServer(c, jujuMetaInstanceServer, "alien")
	addTestClientServer(c, jujuMetaInstanceStateServer, "alien")
	addTestClientServer(c, jujuMetaInstanceServer, "client-test")
	suuid := addTestClientServer(c, jujuMetaInstanceStateServer, "client-test")

	cli, err := testNewClient(c, mock.Endpoint(""), mock.TestUser, mock.TestPassword)
	c.Assert(err, gc.IsNil)

	err = cli.stopInstance(instance.Id(suuid))
	c.Assert(err, gc.IsNil)

	_, err = cli.getStateServerIds()
	c.Check(err, gc.Equals, environs.ErrNotBootstrapped)
}