Esempio 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)
Esempio n. 2
0
    def test_instance_attributes(self):
        mock_server = MockServer("i123", 3)
        mock_flavor = MockFlavor("myflavor")

        self.pyrax.cloudservers.servers.servers["123.com"] = mock_server
        self.pyrax.cloudservers.flavors.flavors[3] = mock_flavor

        with MockSubprocessCall(0, "DFW"):
            self.assertEqual("DFW", self.cloud.location)

        with MockSubprocessCall(0, "123.com"):
            _ = self.cloud.instance  # Prime the cache

        self.assertEqual(mock_server, self.cloud.instance)
        self.assertEqual(mock_flavor.human_id, self.cloud.instance_type)
Esempio n. 3
0
    def test_volumes(self):
        mock_server = MockServer("i123", 3)
        vol1 = MockIncompleteVolume("v1")
        vol2 = MockIncompleteVolume("v2")

        vol1_complete = MockActualVolume(100, [{
            'device': '/dev/xvdb',
            'server_id': '',
            'id': '',
            'volume_id': ''
        }])
        vol2_complete = MockActualVolume(140, [{
            'device': '/dev/xvdc',
            'server_id': '',
            'id': '',
            'volume_id': ''
        }])

        self.pyrax.cloudservers.servers.servers["123.com"] = mock_server
        self.pyrax.cloudservers.volumes.volumes["i123"] = [vol1, vol2]
        self.pyrax.cloud_blockstorage.volumes["v1"] = vol1_complete
        self.pyrax.cloud_blockstorage.volumes["v2"] = vol2_complete

        with MockSubprocessCall(0, "123.com"):
            _ = self.cloud.instance  # Prime the cache

        volumes = self.cloud.attachments
        self.assertEqual(2, len(volumes))

        vol1_loaded, vol2_loaded = volumes

        self.assertEqual("/dev/xvdb", vol1_loaded._cloud_device)
        self.assertEqual(100, vol1_loaded.size)
        self.assertEqual("/dev/xvdc", vol2_loaded._cloud_device)
        self.assertEqual(140, vol2_loaded.size)
Esempio 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__)
Esempio 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))
Esempio 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__)