Exemplo n.º 1
0
    def testNewCloud(self):
        srv = self.newService()
        uri = 'clouds/xen-enterprise/instances'
        client = self.newClient(srv, uri)

        reqData = _xmlNewCloud
        response = client.request('POST', reqData)

        hndl = clouds.Handler()
        node = hndl.parseString(response.read())

        cloudId = "http://%s/TOPLEVEL/clouds/%s/instances/%s" % (
            client.hostport, 'xen-enterprise', 'newbie.eng.rpath.com')
        self.failUnlessEqual(node.getId(), cloudId)
        self.failUnlessEqual(node.getCloudAlias(), 'newbie')
        self.failUnlessEqual(node.getCloudName(), 'newbie.eng.rpath.com')
        self.failUnlessEqual(node.getType().getText(), 'xen-enterprise')

        # Adding it again should fail
        response = self.failUnlessRaises(ResponseError, client.request, 'POST',
                                         reqData)
        self.failUnlessEqual(response.status, 409)
        self.assertXMLEquals(
            response.contents, """
<?xml version='1.0' encoding='UTF-8'?>
<fault>
  <code>409</code>
  <message>Target already exists</message>
</fault>""")

        # Enumerate xen clouds - we should have 3 of them now
        uri = 'clouds/xen-enterprise/instances'
        client = self.newClient(srv, uri)

        response = client.request('GET')
        hndl = clouds.Handler()
        nodes = hndl.parseString(response.read())
        self.failUnlessEqual(len(nodes), 3)
        node = nodes[1]
        self.failUnlessEqual(node.getCloudAlias(), 'newbie')

        # Try to enumerate images - it should fail
        uri = 'clouds/xen-enterprise/instances/newbie.eng.rpath.com/images'
        client = self.newClient(srv, uri)
        resp = self.failUnlessRaises(ResponseError, client.request, 'GET')
        self.failUnlessEqual(resp.status, 400)
        self.assertXMLEquals(
            resp.contents,
            '<?xml version="1.0" encoding="UTF-8"?>\n<fault>\n  <code>400</code>\n  <message>Target credentials not set for user</message>\n</fault>'
        )
Exemplo n.º 2
0
    def testFreezeThaw(self):
        hndlr = clouds.Handler()

        cloudId = "cId"
        cloudName = "cName"

        cloud = clouds.BaseCloud(id=cloudId, cloudName=cloudName)

        self.failUnlessEqual(cloud.getId(), cloudId)
        self.failUnlessEqual(cloud.getCloudName(), cloudName)
        self.failUnlessEqual(cloud.getType(), None)
        self.failUnlessRaises(AttributeError, getattr, cloud, "getADFAdcadf")

        ret = hndlr.toXml(cloud, prettyPrint=False)
        self.failUnlessEqual(
            ret,
            """<?xml version='1.0' encoding='UTF-8'?>\n<cloud id="cId"><cloudName>cName</cloudName></cloud>"""
        )
        x = hndlr.parseString(ret)
        self.failUnlessEqual(x.getId(), cloudId)
        self.failUnlessEqual(x.getCloudName(), cloudName)
        self.failUnlessEqual(x.getType(), None)

        # Multiple nodes
        nodes = clouds.BaseClouds()
        nodes.append(x)

        ret = hndlr.toXml(nodes, prettyPrint=False)
        self.failUnlessEqual(
            ret,
            """<?xml version='1.0' encoding='UTF-8'?>\n<clouds><cloud id="cId"><cloudName>cName</cloudName></cloud></clouds>"""
        )
Exemplo n.º 3
0
    def testRemoveCloud(self):
        srv = self.newService()
        uri = self._baseCloudUrl
        client = self.newClient(srv, uri)

        response = client.request('DELETE')
        hndlr = clouds.Handler()

        self.assertXMLEquals(
            response.read(),
            "<?xml version='1.0' encoding='UTF-8'?>\n<clouds/>")

        # Removing a second time should give a 404
        response = self.failUnlessRaises(ResponseError, client.request,
                                         'DELETE')
        self.failUnlessEqual(response.status, 404)

        # Cloud enumeration should no loger reveal aws
        uri = 'clouds/%s/instances' % self.cloudType
        client = self.newClient(srv, uri)

        response = client.request('GET')
        self.assertXMLEquals(
            response.read(),
            "<?xml version='1.0' encoding='UTF-8'?>\n<clouds/>")

        # Instance enumeration should fail with 404 (bad cloud name)
        uri = self._baseCloudUrl
        client = self.newClient(srv, uri)

        response = self.failUnlessRaises(ResponseError, client.request, 'GET')
        self.failUnlessEqual(response.status, 404)
Exemplo n.º 4
0
    def testRemoveCloud(self):
        srv = self.newService()
        uri = 'clouds/xen-enterprise/instances/abc.eng.rpath.com'
        client = self.newClient(srv, uri)

        response = client.request('DELETE')
        hndlr = clouds.Handler()

        self.assertXMLEquals(
            response.read(),
            "<?xml version='1.0' encoding='UTF-8'?>\n<clouds/>")

        # Removing a second time should give a 404
        response = self.failUnlessRaises(ResponseError, client.request,
                                         'DELETE')
        self.failUnlessEqual(response.status, 404)

        # Cloud enumeration should no loger reveal aws
        uri = 'clouds/xen-enterprise/instances'
        client = self.newClient(srv, uri)

        response = client.request('GET')
        nodes = hndlr.parseString(response.read())
        self.failUnlessEqual(len(nodes), 1)

        # Instance enumeration should fail with 404 (bad cloud name)
        uri = 'clouds/xen-enterprise/instances/abc.eng.rpath.com/instances'
        client = self.newClient(srv, uri)

        response = self.failUnlessRaises(ResponseError, client.request, 'GET')
        self.failUnlessEqual(response.status, 404)
Exemplo n.º 5
0
    def testGetCloudsNoCredentials(self):
        # RBL-3945
        cloudName = 'xs01.eng.rpath.com'
        self.restdb.targetMgr.setTargetCredentialsForUser(
            self.CLOUD_TYPE, cloudName, 'JeanValjean', {})

        srv = self.newService()
        uri = 'clouds/xen-enterprise/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 = clouds.Handler()
        nodes = hndlr.parseString(response.read())

        self.failUnlessEqual([x.getCloudName() for x in nodes],
                             ['abc.eng.rpath.com', 'xs01.eng.rpath.com'])

        prefix = self.makeUri(
            client, "clouds/xen-enterprise/instances/abc.eng.rpath.com")
        self.failUnlessEqual(
            [x.getDescriptorLaunch().getHref() for x in nodes], [
                self.makeUri(
                    client,
                    "clouds/xen-enterprise/instances/%s/descriptor/launch" %
                    (x.getCloudName(), )) for x in nodes
            ])
Exemplo n.º 6
0
    def testGetOneCloud1(self):
        srv = self.newService()
        uri = 'clouds/ec2/instances/aws'

        client = self.newClient(srv, uri)

        response = client.request('GET')
        response = util.BoundedStringIO(response.read())
        hndlr = clouds.Handler()
        nodes = hndlr.parseFile(response)
        self.failUnlessEqual([x.getCloudName() for x in nodes], ['aws'])
Exemplo n.º 7
0
    def _testGetClouds(self, uri, cloudType, expected, method='POST'):
        srv = self.newService()

        client = self.newClient(srv, uri)

        response = client.request(method)
        self.failUnlessEqual(response.msg['Content-Type'], 'application/xml')
        hndlr = clouds.Handler()
        response = util.BoundedStringIO(response.read())
        nodes = hndlr.parseFile(response)

        self.failUnlessEqual([x.getType().getText() for x in nodes],
                             [cloudType] * len(nodes))

        expTypeRefs = [
            "http://%s/TOPLEVEL/clouds/%s" % (client.hostport, cloudType)
        ] * len(nodes)
        self.failUnlessEqual([x.getType().getHref() for x in nodes],
                             expTypeRefs)

        expIds = [
            "http://%s/TOPLEVEL/clouds/%s/instances/%s" %
            (client.hostport, cloudType, x['cloudName']) for x in expected
        ]
        self.failUnlessEqual([x.getId() for x in nodes], expIds)

        self.failUnlessEqual([x.getCloudName() for x in nodes],
                             [x['cloudName'] for x in expected])
        self.failUnlessEqual([x.getCloudAlias() for x in nodes],
                             [x['cloudAlias'] for x in expected])
        self.failUnlessEqual([x.getDescription() for x in nodes],
                             [x['description'] for x in expected])
        self.failUnlessEqual([x.getImages().getHref() for x in nodes],
                             [x + '/images' for x in expIds])
        self.failUnlessEqual([x.getInstances().getHref() for x in nodes],
                             [x + '/instances' for x in expIds])
        self.failUnlessEqual(
            [x.getDescriptorLaunch().getHref() for x in nodes],
            [x + '/descriptor/launch' for x in expIds])
        self.failUnlessEqual([x.getConfiguration().getHref() for x in nodes],
                             [x + '/configuration' for x in expIds])
        self.failUnlessEqual(
            [x.getUserCredentials().getHref() for x in nodes],
            [x + '/users/JeanValjean/credentials' for x in expIds])

        expHrefs = [
            "http://%s/TOPLEVEL/jobs/types/instance-launch/jobs?cloudName=%s&cloudType=%s&status=Running"
            % (client.hostport, x['cloudName'], cloudType) for x in expected
        ]
        self.failUnlessEqual([x.getActiveJobs().getHref() for x in nodes],
                             expHrefs)
Exemplo n.º 8
0
    def testNewCloudWithDeploymentDaemon(self):
        srv = self.newService()
        uri = 'clouds/xen-enterprise/instances'
        client = self.newClient(srv, uri)

        reqData = _xmlNewCloud2
        response = client.request('POST', reqData)

        hndl = clouds.Handler()
        node = hndl.parseString(response.read())

        cloudId = self.makeUri(
            client, "clouds/%s/instances/%s" %
            ('xen-enterprise', 'newbie.eng.rpath.com'))
        self.failUnlessEqual(node.getId(), cloudId)
Exemplo n.º 9
0
    def testGetClouds1(self):
        srv = self.newService()
        uri = 'clouds/%s/instances' % self.cloudType
        client = self.newClient(srv, uri)

        response = client.request('GET')
        hndlr = clouds.Handler()
        response = util.BoundedStringIO(response.read())
        nodes = hndlr.parseFile(response)

        self.failUnlessEqual([x.getCloudName() for x in nodes],
                             [self.cloudName])

        self.failUnlessEqual([x.getCloudAlias() for x in nodes], ['euca1'])

        self.failUnlessEqual([x.getDescription() for x in nodes],
                             ['Eucalyptus server'])
Exemplo n.º 10
0
    def testGetClouds1(self):
        srv = self.newService()
        uri = 'clouds/xen-enterprise/instances'
        client = self.newClient(srv, uri)

        response = client.request('GET')
        hndlr = clouds.Handler()
        response = util.BoundedStringIO(response.read())
        nodes = hndlr.parseFile(response)

        self.failUnlessEqual([x.getCloudName() for x in nodes],
                             ['abc.eng.rpath.com', 'xs01.eng.rpath.com'])

        self.failUnlessEqual([x.getCloudAlias() for x in nodes],
                             ['abc', 'xs01'])

        self.failUnlessEqual([x.getDescription() for x in nodes],
                             ['abc cloud', 'xs01 cloud'])
Exemplo n.º 11
0
    def test1(self):
        raise testsuite.SkipTestException("Apache no longer actively used")
        uri = 'clouds/ec2/instances'
        srv = self.newService()
        client = self.newClient(srv, uri)
        response = client.request("GET")

        self.failUnlessEqual(response.msg['Content-Type'], 'application/xml')
        hndlr = clouds.Handler()
        nodes = hndlr.parseString(response.read())

        raise testsuite.SkipTestException("Need to replace vws")
        expected = [
            'vws/instances/snaily.eng.rpath.com:8443',
            'vws/instances/speedy.eng.rpath.com:8443',
            'vws/instances/tp-grid3.ci.uchicago.edu:8445'
        ]
        for exp, x in zip(expected, nodes):
            self.failUnlessEqual(x.getName(), 'cloud')
            cloudId = x.getId()
            expUrl = "http://%s:%s%s/clouds/%s" % (client.host, client.port,
                                                   self._basePath, exp)
            self.failUnlessEqual(cloudId, expUrl)
Exemplo n.º 12
0
    def testMalformedURI(self):
        # pass a uri that doesn't have an ID (it should) to see if the system
        # tips over or not.
        srv = self.newService()
        uri = 'clouds/ec2/instances?_method=GET'

        client = self.newClient(srv, uri)

        response = client.request('POST')
        self.failUnlessEqual(response.msg['Content-Type'], 'application/xml')
        hndlr = clouds.Handler()
        response = util.BoundedStringIO(response.read())
        nodes = hndlr.parseFile(response)
        self.failUnlessEqual(len(nodes), 1)
        expected = ['ec2/instances/aws']
        self.failUnlessEqual([x.getType().getText() for x in nodes],
                             [x.split('/')[0] for x in expected])
        self.failUnlessEqual([x.getCloudName() for x in nodes],
                             [x.split('/')[2] for x in expected])
        for exp, x in zip(expected, nodes):
            self.failUnlessEqual(x.getName(), 'cloud')
            cloudId = x.getId()
            expUrl = "http://%s/TOPLEVEL/clouds/%s" % (client.hostport, exp)
            self.failUnlessEqual(cloudId, expUrl)