Ejemplo n.º 1
0
    def test_not_found(self):
        self.session.mount("http://169.254.169.254", UnreachableTestAdapter())
        self.session.mount("http://metadata", UnreachableTestAdapter())

        with MockSession(self.session), MockSubprocessCall(0, "Not Rackspace"):
            self.assertRaises(CloudUnavailableError, Cloud)

        with MockSession(self.session), MockSubprocessCall(1, "Rackspace"):
            self.assertRaises(CloudUnavailableError, Cloud)
Ejemplo n.º 2
0
    def test_attachments(self):
        """
        Test that the attachments are:
            - Filtered
            - Returned with the correct mountpoint
        """
        class MockConn(object):
            def __init__(self, volumes):
                self.requests = []
                self.volumes = volumes

            def get_all_volumes(self, filters):
                self.requests.append(filters)
                return self.volumes

        volume1 = self.Volume()
        volume1.attach_data = self.AttachmentSet()
        volume1.status = "in-use"
        volume1.attach_data.device = "/dev/sdg"
        volume1.size = 10

        volume2 = self.Volume()
        volume2.attach_data = self.AttachmentSet()
        volume2.attach_data.device = "/dev/sda"
        volume2.status = "in-use"
        volume2.size = 100
        volume2.iops = 100

        volume3 = self.Volume()
        volume3.status = "attaching"
        volume3.attach_data = self.AttachmentSet()
        volume3.size = 15

        volumes = [volume1, volume2, volume3]

        self.ec2_response._content = "i-1234"
        adapter = RepeatingTestAdapter(self.ec2_response)
        self.session.mount("http://169.254.169.254", adapter)

        with MockSession(self.session):
            cloud = Cloud()

        cloud._conn = MockConn(volumes)

        attachments = cloud.attachments

        with MockPathExists(["/dev/sda", "/dev/xvdg"]):
            self.assertItemsEqual(
                ["/dev/xvdg", "/dev/sda"],
                [attachment.device for attachment in attachments])

        self.assertEqual([True, True],
                         [attachment.persistent for attachment in attachments])

        self.assertEqual(1, len(cloud._conn.requests))
        self.assertDictEqual({"attachment.instance-id": "i-1234"},
                             cloud._conn.requests[0])
        self.assertSequenceEqual(
            [["EBS", "10 GB"], ["EBS", "100 GB", "100 PIOPS"]],
            [attachment.assets for attachment in attachments])
Ejemplo n.º 3
0
    def test_metadata(self):
        # Instance type
        response1 = requests.Response()
        response1.status_code = 200
        response1._content = six.b("m1.large")
        response1.encoding = "utf-8"

        # AZ
        response2 = requests.Response()
        response2.status_code = 200
        response2._content = six.b("us-east-1a")
        response2.encoding = "utf-8"
        # TODO: Add instance ID, and test request paths.

        adapter = PredictableTestAdapter(
            [self.ec2_response, response1, response2, response2])
        self.session.mount("http://169.254.169.254", adapter)

        with MockSession(self.session):
            cloud = Cloud()

        self.assertEqual("m1.large", cloud.instance_type)
        self.assertEqual("us-east-1a", cloud.availability_zone)
        self.assertEqual("us-east-1", cloud.location)
        self.assertEqual(0, len(adapter.responses))
        self.assertEqual("EC2", cloud.provider)
Ejemplo n.º 4
0
    def test_rackspace(self):
        self.session.mount("http://169.254.169.254", UnreachableTestAdapter())
        self.session.mount("http://metadata", UnreachableTestAdapter())

        with MockSession(self.session), MockSubprocessCall(0, "Rackspace"):
            cloud = Cloud()

        self.assertEqual("RackspaceOpenCloud", cloud.__class__.__name__)
Ejemplo n.º 5
0
    def test_metadata(self):
        # Instance type
        response1 = requests.Response()
        response1.status_code = 200
        response1._content = six.b("projects/1234/machineTypes/n1-standard-1-d")
        response1.encoding = "utf-8"

        # AZ
        response2 = requests.Response()
        response2.status_code = 200
        response2._content = six.b("projects/1234/zones/us-central1-b")
        response2.encoding = "utf-8"

        # Attachments
        response3 = requests.Response()
        response3.status_code = 200
        response3._content = six.b('[{"deviceName":"boot","index":0,"mode":"READ_WRITE","type":"EPHEMERAL"},{"deviceName":"ephemeral-disk-0","index":1,"mode":"READ_WRITE","type":"EPHEMERAL"},{"deviceName":"scalr-disk-1a043e80","index":2,"mode":"READ_WRITE","type":"PERSISTENT"}]')
        response3.encoding = "utf-8"


        adapter = PredictableTestAdapter([self.ec2_response, response1, response2, response2, response3])
        self.session.mount("http://metadata", adapter)

        with MockSession(self.session):
            cloud = Cloud()

        self.assertEqual("n1-standard-1-d", cloud.instance_type)
        self.assertEqual("us-central1-b", cloud.availability_zone)
        self.assertEqual("us-central1", cloud.location)
        self.assertEqual("GCE", cloud.provider)

        attachments = cloud.attachments

        with MockPathExists(["/dev/sda", "/dev/sdb", "/dev/sdc"]):
            self.assertSequenceEqual(["/dev/sda", "/dev/sdb", "/dev/sdc"],
                                     [attachment.device for attachment in attachments])

        self.assertSequenceEqual([False, False, True],
                                 [attachment.persistent for attachment in attachments])

        disk_structure = """{
  "creationTimestamp": "2013-09-30T01:14:23.599-07:00",
  "id": "7422554157413993697",
  "kind": "compute#disk",
  "name": "scalr-disk-1a043e80",
  "selfLink": "https://www.googleapis.com/compute/v1beta15/projects/scalr.com:scalr-labs/zones/us-central1-b/disks/scalr-disk-1a043e80",
  "sizeGb": "15",
  "status": "READY",
  "zone": "https://www.googleapis.com/compute/v1beta15/projects/scalr.com:scalr-labs/zones/us-central1-b"
}"""

        with MockSubprocessCall(0, disk_structure):
            self.assertEqual(["GCE Disk", "15 GB"], attachments[2].assets)

        self.assertEqual(0, len(adapter.responses))
Ejemplo n.º 6
0
    def test_gce(self):
        response = requests.Response()
        response.status_code = 200
        adapter = RepeatingTestAdapter(response)

        self.session.mount("http://metadata", adapter)
        self.session.mount("http://169.254.169.254", UnreachableTestAdapter())

        with MockSession(self.session), MockSubprocessCall(0, "Not Rackspace"):
            cloud = Cloud()

        self.assertEqual("GCE", cloud.__class__.__name__)
Ejemplo n.º 7
0
    def test_error_propagation(self):
        response = requests.Response()
        response.status_code = 200
        adapter = RepeatingTestAdapter(response)
        self.session.mount("http://metadata", adapter)

        with MockSession(self.session):
            cloud = Cloud()

        response = requests.Response()
        response.status_code = 500
        adapter = RepeatingTestAdapter(response)
        self.session.mount("http://metadata", adapter)

        self.assertRaises(CloudAPIError, getattr, cloud, "location")