Example #1
0
    def test_current_ami_ssl_verify(self):
        """
        Test that the appropriate SSL verifying context factory is passed.
        """

        def match_context(value):
            if VerifyingContextFactory is None:
                # We're running against an older twisted version without
                # certificate verification.
                return value is None
            return isinstance(value, VerifyingContextFactory)

        page = self.mocker.replace("twisted.web.client.getPage")
        page(IMAGE_URI_TEMPLATE % "lucid",
                contextFactory=MATCH(match_context))
        self.mocker.result(succeed(
            open(os.path.join(IMAGE_DATA_DIR, "lucid.txt")).read()))
        self.mocker.replay()
        d = get_current_ami("lucid", "i386", "us-east-1", False, True)

        def verify_result(result):
            self.assertEqual(result, "ami-714ba518")

        d.addCallback(verify_result)
        return d
Example #2
0
 def test_hvm_request_on_old_series(self):
     page = self.mocker.replace("twisted.web.client.getPage")
     page(IMAGE_URI_TEMPLATE % "lucid", contextFactory=None)
     self.mocker.result(
         succeed(open(
             os.path.join(IMAGE_DATA_DIR, "lucid.txt")).read()))
     self.mocker.replay()
     d = get_current_ami("lucid", "amd64", "us-east-1", True, False)
     self.failUnlessFailure(d, LookupError)
     return d
Example #3
0
 def test_bad_url(self):
     """
     If the requested page doesn't exist at all, a LookupError is raised
     """
     page = self.mocker.replace("twisted.web.client.getPage")
     page(IMAGE_URI_TEMPLATE % "nutty")
     self.mocker.result(fail(Error("404")))
     self.mocker.replay()
     d = get_current_ami(ubuntu_release="nutty")
     self.failUnlessFailure(d, LookupError)
     return d
Example #4
0
 def test_current_ami_with_virtualisation_info(self):
     """The current server machine image can be retrieved by arch."""
     page = self.mocker.replace("twisted.web.client.getPage")
     page(IMAGE_URI_TEMPLATE % "natty", contextFactory=None)
     self.mocker.result(
         succeed(open(
             os.path.join(IMAGE_DATA_DIR, "natty.txt")).read()))
     self.mocker.replay()
     d = get_current_ami("natty", "amd64", "us-east-1", True, False)
     d.addCallback(self.assertEquals, "ami-1cad5275")
     return d
Example #5
0
 def test_current_ami_by_region(self):
     """The current server machine image can be retrieved by region."""
     page = self.mocker.replace("twisted.web.client.getPage")
     page(IMAGE_URI_TEMPLATE % "lucid", contextFactory=None)
     self.mocker.result(
         succeed(open(
             os.path.join(IMAGE_DATA_DIR, "lucid.txt")).read()))
     self.mocker.replay()
     d = get_current_ami("lucid", "i386", "us-west-1", False, False)
     d.addCallback(self.assertEquals, "ami-cb97c68e")
     return d
Example #6
0
 def test_bad_url(self):
     """
     If the requested page doesn't exist at all, a LookupError is raised
     """
     page = self.mocker.replace("twisted.web.client.getPage")
     page(IMAGE_URI_TEMPLATE % "nutty", contextFactory=None)
     self.mocker.result(fail(Error("404")))
     self.mocker.replay()
     d = get_current_ami("nutty", "i386", "us-east-1", False, False)
     self.failUnlessFailure(d, LookupError)
     return d
Example #7
0
 def test_bad_url(self):
     """
     If the requested page doesn't exist at all, a LookupError is raised
     """
     page = self.mocker.replace("twisted.web.client.getPage")
     page(IMAGE_URI_TEMPLATE % "nutty")
     self.mocker.result(fail(Error("404")))
     self.mocker.replay()
     d = get_current_ami(ubuntu_release="nutty")
     self.failUnlessFailure(d, LookupError)
     return d
Example #8
0
 def test_umatched_ami(self):
     """
     If an ami is not found that matches the specifications, then
     a LookupError is raised.
     """
     page = self.mocker.replace("twisted.web.client.getPage")
     page(IMAGE_URI_TEMPLATE % "lucid")
     self.mocker.result(succeed(""))
     self.mocker.replay()
     d = get_current_ami(ubuntu_release="lucid")
     self.failUnlessFailure(d, LookupError)
     return d
Example #9
0
 def test_umatched_ami(self):
     """
     If an ami is not found that matches the specifications, then
     a LookupError is raised.
     """
     page = self.mocker.replace("twisted.web.client.getPage")
     page(IMAGE_URI_TEMPLATE % "lucid", contextFactory=None)
     self.mocker.result(succeed(""))
     self.mocker.replay()
     d = get_current_ami("lucid", "i386", "us-east-1", False, False)
     self.failUnlessFailure(d, LookupError)
     return d
Example #10
0
 def test_umatched_ami(self):
     """
     If an ami is not found that matches the specifications, then
     a LookupError is raised.
     """
     page = self.mocker.replace("twisted.web.client.getPage")
     page(IMAGE_URI_TEMPLATE % "lucid")
     self.mocker.result(succeed(""))
     self.mocker.replay()
     d = get_current_ami(ubuntu_release="lucid")
     self.failUnlessFailure(d, LookupError)
     return d
Example #11
0
    def test_current_ami_by_region(self):
        """The current server machine image can be retrieved by region."""
        page = self.mocker.replace("twisted.web.client.getPage")
        page(IMAGE_URI_TEMPLATE % "lucid")
        self.mocker.result(
            succeed(open(os.path.join(IMAGE_DATA_DIR, "lucid.txt")).read()))
        self.mocker.replay()
        d = get_current_ami(ubuntu_release="lucid", region="us-west-1")

        def verify_result(result):
            self.assertEqual(result, "ami-cb97c68e")

        d.addCallback(verify_result)
        return d
Example #12
0
    def test_current_ami_by_region(self):
        """The current server machine image can be retrieved by region."""
        page = self.mocker.replace("twisted.web.client.getPage")
        page(IMAGE_URI_TEMPLATE % "lucid")
        self.mocker.result(
            succeed(open(
                os.path.join(IMAGE_DATA_DIR, "lucid.txt")).read()))
        self.mocker.replay()
        d = get_current_ami(ubuntu_release="lucid", region="us-west-1")

        def verify_result(result):
            self.assertEqual(result, "ami-cb97c68e")

        d.addCallback(verify_result)
        return d
Example #13
0
    def test_current_ami_non_ebs(self):
        """
        The get_current_ami function accepts several filtering parameters
        to guide image selection.
        """
        page = self.mocker.replace("twisted.web.client.getPage")
        page(IMAGE_URI_TEMPLATE % "lucid")
        self.mocker.result(
            succeed(open(os.path.join(IMAGE_DATA_DIR, "lucid.txt")).read()))
        self.mocker.replay()
        d = get_current_ami(ubuntu_release="lucid", persistent_storage=False)

        def verify_result(result):
            self.assertEqual(result, "ami-2d4aa444")

        d.addCallback(verify_result)
        return d
Example #14
0
    def test_current_ami_non_ebs(self):
        """
        The get_current_ami function accepts several filtering parameters
        to guide image selection.
        """
        page = self.mocker.replace("twisted.web.client.getPage")
        page(IMAGE_URI_TEMPLATE % "lucid")
        self.mocker.result(succeed(
            open(os.path.join(IMAGE_DATA_DIR, "lucid.txt")).read()))
        self.mocker.replay()
        d = get_current_ami(ubuntu_release="lucid", persistent_storage=False)

        def verify_result(result):
            self.assertEqual(result, "ami-2d4aa444")

        d.addCallback(verify_result)
        return d