Beispiel #1
0
    def testFreezeThaw(self):
        hndlr = instances.Handler()

        instId = "ec2-adfadf"
        instVal = "someval"

        instance = instances.BaseInstance(id=instId, state=instVal)

        self.failUnlessEqual(instance.getId(), instId)
        self.failUnlessEqual(instance.getShutdownState(), None)
        self.failUnlessEqual(instance.getState(), instVal)
        self.failUnlessRaises(AttributeError, getattr, instance,
                              "getADFAdcadf")

        ret = hndlr.toXml(instance, prettyPrint=False)
        self.failUnlessEqual(
            ret,
            """<?xml version='1.0' encoding='UTF-8'?>\n<instance id="ec2-adfadf" xmlNodeHash="1a837d8c26533d24be7184cf5ebb8a00886a85ff"><state>someval</state></instance>"""
        )
        x = hndlr.parseString(ret)
        self.failUnlessEqual(x.getId(), instId)
        self.failUnlessEqual(x.getShutdownState(), None)
        self.failUnlessEqual(x.getState(), instVal)

        # Multiple nodes
        insts = instances.BaseInstances()
        insts.append(x)

        ret = hndlr.toXml(insts, prettyPrint=False)
        self.failUnlessEqual(
            ret,
            """<?xml version='1.0' encoding='UTF-8'?>\n<instances><instance id="ec2-adfadf" xmlNodeHash="1a837d8c26533d24be7184cf5ebb8a00886a85ff"><state>someval</state></instance></instances>"""
        )
        # XXX this has to change - we need to parse these objects
        return
Beispiel #2
0
    def testNewInstances1(self):
        cloudName = 'xs01.eng.rpath.com'
        cloudType = xenent.driver.cloudType

        def fakeDaemonize(*args, **kwargs):
            pass

        srv, client, job, response = self._setUpNewInstanceTest(
            cloudName, fakeDaemonize, '')

        jobUrlPath = 'jobs/types/instance-launch/jobs/1'
        self.failUnlessEqual(job.get_id(), self.makeUri(client, jobUrlPath))
        self.failUnlessEqual(
            job.get_imageId(),
            self.makeUri(
                client,
                "clouds/xen-enterprise/instances/xs01.eng.rpath.com/images/0903de41206786d4407ff24ab6e972c0d6b801f3"
            ))

        # Enumerate instances
        response = client.request('GET')
        hndlr = instances.Handler()
        nodes = hndlr.parseString(response.read())

        self.failUnlessEqual(len(nodes), 6)

        # Grab the job
        client = self.newClient(srv, jobUrlPath)
        response = client.request('GET')

        job = self.getJobFromResponse(response)

        self.failUnlessEqual(job.get_id(), self.makeUri(client, jobUrlPath))
Beispiel #3
0
    def testChecksum(self):
        hndlr = instances.Handler()

        instId = "blah blah blah"
        instLocation = "Location"
        instState = "Pending"
        instance = instances.BaseInstance(id=instId,
                                          location=instLocation,
                                          state=instState)

        ret = hndlr.toXml(instance, prettyPrint=False)
        self.failUnlessEqual(
            ret,
            """<?xml version='1.0' encoding='UTF-8'?>\n<instance id="blah blah blah" xmlNodeHash="5b37fd4919b3c3d1bf6a9295175f33f52a78111b"><state>Pending</state></instance>"""
        )

        instState = "Running"
        instance = instances.BaseInstance(id=instId,
                                          location=instLocation,
                                          state=instState)

        ret = hndlr.toXml(instance, prettyPrint=False)
        self.failUnlessEqual(
            ret,
            """<?xml version='1.0' encoding='UTF-8'?>\n<instance id="blah blah blah" xmlNodeHash="484471a6a17481fcfd7ecf821833928c8679b392"><state>Running</state></instance>"""
        )
Beispiel #4
0
    def testFreezeInstanceTypes(self):
        hndlr = instances.Handler()

        instTypes = instances.InstanceTypes()
        instTypes.extend(
            instances.InstanceType(id=x, description=y)
            for (x, y) in [('a', 'aa'), ('b', 'bb')])
        ret = hndlr.toXml(instTypes, prettyPrint=False)
        self.failUnlessEqual(
            ret,
            """<?xml version='1.0' encoding='UTF-8'?>\n<instanceTypes><instanceType id="a"><description>aa</description></instanceType><instanceType id="b"><description>bb</description></instanceType></instanceTypes>"""
        )
Beispiel #5
0
    def testGetInstance1(self):
        srv = self.newService()
        instId = '9b01f3fb-3e66-4c0b-9a8f-3c8ea1a6769e'
        uri = 'clouds/xen-enterprise/instances/xs01.eng.rpath.com/instances'
        uri += '/' + instId
        client = self.newClient(srv, uri)

        response = client.request('GET')
        hndlr = instances.Handler()
        node = hndlr.parseString(response.read())

        # Normally we should only get one instance, but the call is mocked
        self.failUnlessEqual(node.getInstanceId(), instId)
Beispiel #6
0
    def testTerminateEC2InstancesPOST(self):
        instanceId = 'i-60f12709'

        srv = self.newService()
        uri = 'clouds/ec2/instances/aws/instances/%s?_method=DELETE' % instanceId
        client = self.newClient(srv, uri)
        response = client.request('POST', mockedData.xml_terminateInstance1)
        hndlr = instances.Handler()
        response = util.BoundedStringIO(response.read())
        node = hndlr.parseFile(response)
        self.failUnless(isinstance(node, instances.BaseInstance), node)
        self.failUnlessEqual(
            node.getId(),
            self.makeUri(client,
                         'clouds/ec2/instances/aws/instances/' + instanceId))
Beispiel #7
0
    def testTerminateInstance(self):
        cloudName = 'xs01.eng.rpath.com'
        cloudType = xenent.driver.cloudType

        instId = '98aef2dc-e6f3-803c-f490-791b847d3a3e'
        srv = self.newService()
        uri = 'clouds/%s/instances/%s/instances/%s' % (cloudType, cloudName,
                                                       instId)

        client = self.newClient(srv, uri)
        response = client.request('DELETE')

        hndlr = instances.Handler()
        nodes = hndlr.parseString(response.read())
        self.failUnlessEqual([x.getState() for x in nodes], ['Terminating'])
Beispiel #8
0
    def testGetNoInstances(self):
        # ensure listing instances when there are none actually returns
        def FakeGetAllInstances(*args, **kwargs):
            return boto.resultset.ResultSet()

        from catalogService.rest.drivers.ec2.ec2client import EC2Connection
        self.mock(EC2Connection, 'get_all_instances', FakeGetAllInstances)
        srv = self.newService()
        uri = 'clouds/ec2/instances/aws/instances?_method=GET'
        client = self.newClient(srv, uri)

        response = client.request('POST')
        self.failUnlessEqual(response.msg['Content-Type'], 'application/xml')
        hndlr = instances.Handler()
        response = util.BoundedStringIO(response.read())
        node = hndlr.parseFile(response)
        self.failUnless(isinstance(node, instances.BaseInstances), node)
        self.failUnlessEqual(len(node), 0)
Beispiel #9
0
    def testGetInstances1(self):
        srv = self.newService()
        uri = 'clouds/xen-enterprise/instances/xs01.eng.rpath.com/instances'
        client = self.newClient(srv, uri)

        response = client.request('GET')
        self.failUnlessEqual(response.msg['Content-Type'], 'application/xml')
        self.failUnlessEqual(response.msg['Cache-Control'], 'no-store')
        hndlr = instances.Handler()
        nodes = hndlr.parseString(response.read())
        self.failUnless(isinstance(nodes, instances.BaseInstances), nodes)

        self.failUnlessEqual([x.getInstanceId() for x in nodes], [
            '0a5bb7f9-8b2b-436e-8e5f-e157101ce7f1', 'VmUuid1',
            'c1af2f03-2e0c-0807-9447-9883c578aa32',
            '98aef2dc-e6f3-803c-f490-791b847d3a3e',
            '9b01f3fb-3e66-4c0b-9a8f-3c8ea1a6769e',
            '1fce577a-f49c-f956-cbdf-45ffae28fd02'
        ])

        self.failUnlessEqual([x.getInstanceName() for x in nodes], [
            'rPath Appliance Platform - Linux Service import',
            'rPath Appliance Platform - Linux Service import (1)',
            'Support Issue replication import (1)',
            'rpath update service import',
            'Control domain on host: localhost.localdomain',
            'Support Issue replication import'
        ])
        self.failUnlessEqual([x.getInstanceDescription() for x in nodes], [
            'Created by rPath rBuilder', 'Created by rPath rBuilder',
            'Created by rPath rBuilder', 'Created by rPath rBuilder',
            'The domain which manages physical devices and manages other domains',
            'Created by rPath rBuilder'
        ])
        self.failUnlessEqual(
            [x.getPublicDnsName() for x in nodes],
            [None, '10.0.0.1', None, '10.0.0.2', '10.0.0.1', None])
        self.failUnlessEqual(
            [x.getState() for x in nodes],
            ['Halted', 'Halted', 'Halted', 'Running', 'Running', 'Suspended'])

        self.failUnlessEqual([x.getLaunchTime() for x in nodes],
                             [None, None, None, '1236348916', None, None])