예제 #1
0
    def test_install_chef_from_omnibus_retries_url(self, m_subp_blob, m_rdurl):
        """install_chef_from_omnibus retries OMNIBUS_URL upon failure."""

        class FakeURLResponse(object):
            contents = '#!/bin/bash\necho "Hi Mom" > {0}/chef.out'.format(
                self.new_root)

        m_rdurl.return_value = FakeURLResponse()

        cc_chef.install_chef_from_omnibus()
        expected_kwargs = {'retries': cc_chef.OMNIBUS_URL_RETRIES,
                           'url': cc_chef.OMNIBUS_URL}
        self.assertItemsEqual(expected_kwargs, m_rdurl.call_args_list[0][1])
        cc_chef.install_chef_from_omnibus(retries=10)
        expected_kwargs = {'retries': 10,
                           'url': cc_chef.OMNIBUS_URL}
        self.assertItemsEqual(expected_kwargs, m_rdurl.call_args_list[1][1])
        expected_subp_kwargs = {
            'args': ['-v', '2.0'],
            'basename': 'chef-omnibus-install',
            'blob': m_rdurl.return_value.contents,
            'capture': False
        }
        self.assertItemsEqual(
            expected_subp_kwargs,
            m_subp_blob.call_args_list[0][1])
예제 #2
0
    def test_install_chef_from_omnibus_retries_url(self, m_subp_blob, m_rdurl):
        """install_chef_from_omnibus retries OMNIBUS_URL upon failure."""

        class FakeURLResponse(object):
            contents = '#!/bin/bash\necho "Hi Mom" > {0}/chef.out'.format(
                self.new_root
            )

        m_rdurl.return_value = FakeURLResponse()

        cc_chef.install_chef_from_omnibus()
        expected_kwargs = {
            "retries": cc_chef.OMNIBUS_URL_RETRIES,
            "url": cc_chef.OMNIBUS_URL,
        }
        self.assertCountEqual(expected_kwargs, m_rdurl.call_args_list[0][1])
        cc_chef.install_chef_from_omnibus(retries=10)
        expected_kwargs = {"retries": 10, "url": cc_chef.OMNIBUS_URL}
        self.assertCountEqual(expected_kwargs, m_rdurl.call_args_list[1][1])
        expected_subp_kwargs = {
            "args": ["-v", "2.0"],
            "basename": "chef-omnibus-install",
            "blob": m_rdurl.return_value.contents,
            "capture": False,
        }
        self.assertCountEqual(
            expected_subp_kwargs, m_subp_blob.call_args_list[0][1]
        )
예제 #3
0
    def test_install_chef_from_omnibus_runs_chef_url_content(self):
        """install_chef_from_omnibus calls subp_blob_in_tempfile."""
        response = b'#!/bin/bash\necho "Hi Mom"'
        httpretty.register_uri(
            httpretty.GET, cc_chef.OMNIBUS_URL, body=response, status=200
        )
        ret = (None, None)  # stdout, stderr but capture=False

        with mock.patch(
            "cloudinit.config.cc_chef.subp_blob_in_tempfile", return_value=ret
        ) as m_subp_blob:
            cc_chef.install_chef_from_omnibus()
        # admittedly whitebox, but assuming subp_blob_in_tempfile works
        # this should be fine.
        self.assertEqual(
            [
                mock.call(
                    blob=response,
                    args=[],
                    basename="chef-omnibus-install",
                    capture=False,
                )
            ],
            m_subp_blob.call_args_list,
        )
예제 #4
0
    def test_install_chef_from_omnibus_retries_url(self, m_subp_blob, m_rdurl):
        """install_chef_from_omnibus retries OMNIBUS_URL upon failure."""

        class FakeURLResponse(object):
            contents = '#!/bin/bash\necho "Hi Mom" > {0}/chef.out'.format(
                self.new_root)

        m_rdurl.return_value = FakeURLResponse()

        cc_chef.install_chef_from_omnibus()
        expected_kwargs = {'retries': cc_chef.OMNIBUS_URL_RETRIES,
                           'url': cc_chef.OMNIBUS_URL}
        self.assertItemsEqual(expected_kwargs, m_rdurl.call_args_list[0][1])
        cc_chef.install_chef_from_omnibus(retries=10)
        expected_kwargs = {'retries': 10,
                           'url': cc_chef.OMNIBUS_URL}
        self.assertItemsEqual(expected_kwargs, m_rdurl.call_args_list[1][1])
        expected_subp_kwargs = {
            'args': ['-v', '2.0'],
            'basename': 'chef-omnibus-install',
            'blob': m_rdurl.return_value.contents,
            'capture': False
        }
        self.assertItemsEqual(
            expected_subp_kwargs,
            m_subp_blob.call_args_list[0][1])
예제 #5
0
 def test_install_chef_from_omnibus_runs_chef_url_content(self):
     """install_chef_from_omnibus runs downloaded OMNIBUS_URL as script."""
     chef_outfile = self.tmp_path('chef.out', self.new_root)
     response = '#!/bin/bash\necho "Hi Mom" > {0}'.format(chef_outfile)
     httpretty.register_uri(
         httpretty.GET, cc_chef.OMNIBUS_URL, body=response, status=200)
     cc_chef.install_chef_from_omnibus()
     self.assertEqual('Hi Mom\n', util.load_file(chef_outfile))
예제 #6
0
    def test_install_chef_from_omnibus_has_omnibus_version(self, m_subp_blob):
        """install_chef_from_omnibus provides version arg to OMNIBUS_URL."""
        chef_outfile = self.tmp_path('chef.out', self.new_root)
        response = '#!/bin/bash\necho "Hi Mom" > {0}'.format(chef_outfile)
        httpretty.register_uri(
            httpretty.GET, cc_chef.OMNIBUS_URL, body=response)
        cc_chef.install_chef_from_omnibus(omnibus_version='2.0')

        called_kwargs = m_subp_blob.call_args_list[0][1]
        expected_kwargs = {
            'args': ['-v', '2.0'],
            'basename': 'chef-omnibus-install',
            'blob': response,
            'capture': False
        }
        self.assertItemsEqual(expected_kwargs, called_kwargs)
예제 #7
0
    def test_install_chef_from_omnibus_has_omnibus_version(self, m_subp_blob):
        """install_chef_from_omnibus provides version arg to OMNIBUS_URL."""
        chef_outfile = self.tmp_path('chef.out', self.new_root)
        response = '#!/bin/bash\necho "Hi Mom" > {0}'.format(chef_outfile)
        httpretty.register_uri(
            httpretty.GET, cc_chef.OMNIBUS_URL, body=response)
        cc_chef.install_chef_from_omnibus(omnibus_version='2.0')

        called_kwargs = m_subp_blob.call_args_list[0][1]
        expected_kwargs = {
            'args': ['-v', '2.0'],
            'basename': 'chef-omnibus-install',
            'blob': response,
            'capture': False
        }
        self.assertItemsEqual(expected_kwargs, called_kwargs)
예제 #8
0
    def test_install_chef_from_omnibus_runs_chef_url_content(self):
        """install_chef_from_omnibus calls subp_blob_in_tempfile."""
        response = b'#!/bin/bash\necho "Hi Mom"'
        httpretty.register_uri(
            httpretty.GET, cc_chef.OMNIBUS_URL, body=response, status=200)
        ret = (None, None)  # stdout, stderr but capture=False

        with mock.patch("cloudinit.config.cc_chef.util.subp_blob_in_tempfile",
                        return_value=ret) as m_subp_blob:
            cc_chef.install_chef_from_omnibus()
        # admittedly whitebox, but assuming subp_blob_in_tempfile works
        # this should be fine.
        self.assertEqual(
            [mock.call(blob=response, args=[], basename='chef-omnibus-install',
                       capture=False)],
            m_subp_blob.call_args_list)
예제 #9
0
    def test_install_chef_from_omnibus_has_omnibus_version(self, m_subp_blob):
        """install_chef_from_omnibus provides version arg to OMNIBUS_URL."""
        chef_outfile = self.tmp_path("chef.out", self.new_root)
        response = '#!/bin/bash\necho "Hi Mom" > {0}'.format(chef_outfile)
        httpretty.register_uri(
            httpretty.GET, cc_chef.OMNIBUS_URL, body=response
        )
        cc_chef.install_chef_from_omnibus(omnibus_version="2.0")

        called_kwargs = m_subp_blob.call_args_list[0][1]
        expected_kwargs = {
            "args": ["-v", "2.0"],
            "basename": "chef-omnibus-install",
            "blob": response,
            "capture": False,
        }
        self.assertCountEqual(expected_kwargs, called_kwargs)