Example #1
0
    def setup_method(self, method):
        self.config = Config()
        self.config.plugins = Config()

        # TODO: this is fragile as it may depend on the dir the tests were run from
        self.config.plugins[
            'aminator.plugins.provisioner.apt'] = self.config.from_file(
                yaml_file=
                'aminator/plugins/provisioner/default_conf/aminator.plugins.provisioner.apt.yml'
            )

        log.info(self.config.plugins)
        self.plugin = AptProvisionerPlugin()

        self.plugin._config = self.config

        config = self.plugin._config.plugins[
            'aminator.plugins.provisioner.apt']

        # use /tmp if not configured, ideally to use tempfile, but needs C build
        self.full_path = os.path.join(
            config.get('mountpoint', '/tmp'),
            config.get('policy_file_path', '/usr/sbin'),
            config.get('policy_file', 'policy-rc.d'))

        self.plugin._root_mountspec = MountSpec(
            None, None, config.get('mountpoint', '/tmp'), None)

        # cleanup
        if os.path.isfile(self.full_path):
            os.remove(self.full_path)
 def setup_method(self, method):
     self.chef_provisioner = AptChefProvisionerPlugin()
     self.chef_provisioner._config = Config()
     self.chef_provisioner._config.context = Config()
     self.chef_provisioner._config.context.chef = Config()
     self.chef_provisioner._config.context.package = Config()
     self.chef_provisioner._config.pkg_attributes = ['name', 'version', 'release', 'build_job', 'build_number']
     self.chef_provisioner._config.context.chef.dir = "./tests"
     self.chef_provisioner._config.context.chef.json = "test_chef_node.json"
    def setup_method(self, method):
        self.config = Config()
        self.config.plugins = Config()

        # TODO: this is fragile as it may depend on the dir the tests were run from
        self.config.plugins['aminator.plugins.provisioner.apt'] = self.config.from_file(yaml_file='aminator/plugins/provisioner/default_conf/aminator.plugins.provisioner.apt.yml')

        log.info(self.config.plugins)
        self.plugin = AptProvisionerPlugin()

        self.plugin._config = self.config

        config = self.plugin._config.plugins['aminator.plugins.provisioner.apt']

        # use /tmp if not configured, ideally to use tempfile, but needs C build
        self.full_path = os.path.join(
            config.get('mountpoint', '/tmp'),
            config.get('policy_file_path', '/usr/sbin'),
            config.get('policy_file', 'policy-rc.d'))

        self.plugin._root_mountspec = MountSpec(None, None, config.get('mountpoint', '/tmp'), None)

        # cleanup
        if os.path.isfile(self.full_path):
            os.remove(self.full_path)
    def setup_method(self, method):
        self.config = Config()
        self.config.plugins = Config()
        self.config.plugins['aminator.plugins.provisioner.yum'] = self.config.from_file(yaml_file='yum_test.yml')

        self.plugin = YumProvisionerPlugin()
        self.plugin._config = self.config
Example #5
0
class TestAptProvisionerPlugin(object):
    def setup_method(self, method):
        self.config = Config()
        self.config.plugins = Config()

        # TODO: this is fragile as it may depend on the dir the tests were run from
        self.config.plugins[
            'aminator.plugins.provisioner.apt'] = self.config.from_file(
                yaml_file=
                'aminator/plugins/provisioner/default_conf/aminator.plugins.provisioner.apt.yml'
            )

        log.info(self.config.plugins)
        self.plugin = AptProvisionerPlugin()

        self.plugin._config = self.config

        config = self.plugin._config.plugins[
            'aminator.plugins.provisioner.apt']

        # use /tmp if not configured, ideally to use tempfile, but needs C build
        self.full_path = config.get('mountpoint', '/tmp') + "/" + \
                         config.get('policy_file_path', '/usr/sbin') + "/" + \
                         config.get('policy_file', 'policy-rc.d')

        self.plugin._mountpoint = config.get('mountpoint', '/tmp')

        # cleanup
        if os.path.isfile(self.full_path):
            os.remove(self.full_path)

    def test_disable_enable_service_startup(self):
        assert self.plugin._deactivate_provisioning_service_block()
        assert os.path.isfile(self.full_path)

        with open(self.full_path) as f:
            content = f.readlines()

        # remove whitespace and newlines
        content = map(lambda s: s.strip(), content)
        # also remove whitespace and newlines
        original_content = self.config.plugins[
            'aminator.plugins.provisioner.apt'].get(
                'policy_file_content').splitlines()

        assert original_content == content

        assert self.plugin._activate_provisioning_service_block()
        assert False == os.path.isfile(self.full_path)
    def setup_method(self, method):
        self.config = Config()
        self.config.plugins = Config()
        self.config.plugins['aminator.plugins.provisioner.apt'] = self.config.from_file(yaml_file='apt_test.yml')

        self.plugin = AptProvisionerPlugin()
        self.plugin._config = self.config

        config = self.plugin._config.plugins['aminator.plugins.provisioner.apt']

        self.full_path = config.get('mountpoint', '/tmp') + "/" + \
                         config.get('policy_file_path', '/usr/sbin') + "/" + \
                         config.get('policy_file', 'policy-rc.d')

        self.plugin._mountpoint = config.get('mountpoint', '/tmp')
        if os.path.isfile(self.full_path):
            os.remove(self.full_path)
class TestAptProvisionerPlugin(object):

    def setup_method(self, method):
        self.config = Config()
        self.config.plugins = Config()

        # TODO: this is fragile as it may depend on the dir the tests were run from
        self.config.plugins['aminator.plugins.provisioner.apt'] = self.config.from_file(yaml_file='aminator/plugins/provisioner/default_conf/aminator.plugins.provisioner.apt.yml')

        log.info(self.config.plugins)
        self.plugin = AptProvisionerPlugin()

        self.plugin._config = self.config

        config = self.plugin._config.plugins['aminator.plugins.provisioner.apt']

        # use /tmp if not configured, ideally to use tempfile, but needs C build
        self.full_path = config.get('mountpoint', '/tmp') + "/" + \
                         config.get('policy_file_path', '/usr/sbin') + "/" + \
                         config.get('policy_file', 'policy-rc.d')

        self.plugin._mountpoint = config.get('mountpoint', '/tmp')

        # cleanup
        if os.path.isfile(self.full_path):
            os.remove(self.full_path)

    def test_disable_enable_service_startup(self):
        assert self.plugin._deactivate_provisioning_service_block()
        assert os.path.isfile(self.full_path)

        with open(self.full_path) as f:
            content = f.readlines()

        # remove whitespace and newlines
        content = map(lambda s: s.strip(), content)
        # also remove whitespace and newlines
        original_content = self.config.plugins['aminator.plugins.provisioner.apt'].get('policy_file_content').splitlines()

        assert original_content == content

        assert self.plugin._activate_provisioning_service_block()
        assert False == os.path.isfile(self.full_path)
class TestYumProvisionerPlugin(object):

    def setup_method(self, method):
        self.config = Config()
        self.config.plugins = Config()
        self.config.plugins['aminator.plugins.provisioner.yum'] = self.config.from_file(yaml_file='yum_test.yml')

        self.plugin = YumProvisionerPlugin()
        self.plugin._config = self.config

    def test_deactivate_active_services(self):

        files = self.plugin._config.plugins['aminator.plugins.provisioner.yum'].get('short_circuit_files', [])

        if len(files) != 1:
            raise AttributeError("incorrect number of files specified.  found %d expected 1", len(files))

        filename = files[0]

        if not os.path.isdir(os.path.dirname(filename)):
            os.makedirs(os.path.dirname(filename))

        # cleanup
        if os.path.islink(filename):
            log.debug("removing %s", filename)
            os.remove(filename)

        with open(filename, 'w') as f:
            log.debug("writing %s", filename)
            f.write("test")
            log.debug("wrote %s", filename)

        assert self.plugin._deactivate_provisioning_service_block()
        assert True == os.path.islink('/tmp/sbin/service')
        assert self.plugin._activate_provisioning_service_block()
        assert False == os.path.islink('/tmp/sbin/service')
class TestAptProvisionerPlugin(object):

    def setup_method(self, method):
        self.config = Config()
        self.config.plugins = Config()
        self.config.plugins['aminator.plugins.provisioner.apt'] = self.config.from_file(yaml_file='apt_test.yml')

        self.plugin = AptProvisionerPlugin()
        self.plugin._config = self.config

        config = self.plugin._config.plugins['aminator.plugins.provisioner.apt']

        self.full_path = config.get('mountpoint', '/tmp') + "/" + \
                         config.get('policy_file_path', '/usr/sbin') + "/" + \
                         config.get('policy_file', 'policy-rc.d')

        self.plugin._mountpoint = config.get('mountpoint', '/tmp')
        if os.path.isfile(self.full_path):
            os.remove(self.full_path)

    def test_disable_enable_service_startup(self):
        assert self.plugin._deactivate_provisioning_service_block()
        assert os.path.isfile(self.full_path)

        with open(self.full_path) as f:
            content = f.readlines()

        # remove whitespace and newlines
        content = map(lambda s: s.strip(), content)
        # also remove whitespace and newlines
        original_content = self.config.plugins['aminator.plugins.provisioner.apt'].get('policy_file_content').splitlines()

        assert original_content == content

        assert self.plugin._activate_provisioning_service_block()
        assert False == os.path.isfile(self.full_path)
Example #10
0
class TestAptProvisionerPlugin(object):
    def setup_method(self, method):
        self.config = Config()
        self.config.plugins = Config()

        # TODO: this is fragile as it may depend on the dir the tests were run from
        self.config.plugins[
            'aminator.plugins.provisioner.apt'] = self.config.from_file(
                yaml_file=
                'aminator/plugins/provisioner/default_conf/aminator.plugins.provisioner.apt.yml'
            )

        log.info(self.config.plugins)
        self.plugin = AptProvisionerPlugin()

        self.plugin._config = self.config

        config = self.plugin._config.plugins[
            'aminator.plugins.provisioner.apt']

        # use /tmp if not configured, ideally to use tempfile, but needs C build
        self.full_path = os.path.join(
            config.get('mountpoint', '/tmp'),
            config.get('policy_file_path', '/usr/sbin'),
            config.get('policy_file', 'policy-rc.d'))

        self.plugin._root_mountspec = MountSpec(
            None, None, config.get('mountpoint', '/tmp'), None)

        # cleanup
        if os.path.isfile(self.full_path):
            os.remove(self.full_path)

    def test_disable_enable_service_startup(self):
        assert self.plugin._deactivate_provisioning_service_block()
        assert os.path.isfile(self.full_path)

        with open(self.full_path) as f:
            content = f.readlines()

        # remove whitespace and newlines
        content = map(lambda s: s.strip(), content)
        # also remove whitespace and newlines
        original_content = self.config.plugins[
            'aminator.plugins.provisioner.apt'].get(
                'policy_file_content').splitlines()

        assert original_content == content

        assert self.plugin._activate_provisioning_service_block()
        assert os.path.isfile(self.full_path)

    def test_metadata(self):
        """ test that given we get back the metadata we expect
            this first was a problem when the deb Description field had leading whitespace
            which caused the keys to contain leading whitespace
        """

        response = Response()
        response.std_out = """
  Package: helloWorld
  Source: helloWorld
  Version: 1374197704:1.0.0-h357.6ea8a16
  Section: None
  Priority: optional
  Architecture: all
  Provides: helloWorld
  Installed-Size: 102704
  Maintainer: [email protected]
  Description: helloWorld
   ----------
   Manifest-Version: 1.1
   Implementation-Vendor: Hello, Inc.
   Implementation-Title: helloWorld;1.0.0
   Implementation-Version: 1.0.0
   Label: helloWorld-1.0.0
   Built-By: builder
   Build-Job: JOB-helloWorld
   Build-Date: 2013-07-19_01:33:52
   Build-Number: 357
   Build-Id: 2013-07-18_18-24-53
   Change: 6ea8a16
"""
        package_query_result = CommandResult(True, response)
        result = parse_command_result(package_query_result)

        assert result['Build-Number'] == '357'
        assert result['Build-Job'] == 'JOB-helloWorld'
class TestAptProvisionerPlugin(object):

    def setup_method(self, method):
        self.config = Config()
        self.config.plugins = Config()

        # TODO: this is fragile as it may depend on the dir the tests were run from
        self.config.plugins['aminator.plugins.provisioner.apt'] = self.config.from_file(yaml_file='aminator/plugins/provisioner/default_conf/aminator.plugins.provisioner.apt.yml')

        log.info(self.config.plugins)
        self.plugin = AptProvisionerPlugin()

        self.plugin._config = self.config

        config = self.plugin._config.plugins['aminator.plugins.provisioner.apt']

        # use /tmp if not configured, ideally to use tempfile, but needs C build
        self.full_path = config.get('mountpoint', '/tmp') + "/" + \
                         config.get('policy_file_path', '/usr/sbin') + "/" + \
                         config.get('policy_file', 'policy-rc.d')

        self.plugin._mountpoint = config.get('mountpoint', '/tmp')

        # cleanup
        if os.path.isfile(self.full_path):
            os.remove(self.full_path)

    def test_disable_enable_service_startup(self):
        assert self.plugin._deactivate_provisioning_service_block()
        assert os.path.isfile(self.full_path)

        with open(self.full_path) as f:
            content = f.readlines()

        # remove whitespace and newlines
        content = map(lambda s: s.strip(), content)
        # also remove whitespace and newlines
        original_content = self.config.plugins['aminator.plugins.provisioner.apt'].get('policy_file_content').splitlines()

        assert original_content == content

        assert self.plugin._activate_provisioning_service_block()
        assert False == os.path.isfile(self.full_path)

    def test_metadata(self):
        """ test that given we get back the metadata we expect
            this first was a problem when the deb Description field had leading whitespace
            which caused the keys to contain leading whitespace
        """

        response = Response()
        response.std_out = """
  Package: helloWorld
  Source: helloWorld
  Version: 1374197704:1.0.0-h357.6ea8a16
  Section: None
  Priority: optional
  Architecture: all
  Provides: helloWorld
  Installed-Size: 102704
  Maintainer: [email protected]
  Description: helloWorld
   ----------
   Manifest-Version: 1.1
   Implementation-Vendor: Hello, Inc.
   Implementation-Title: helloWorld;1.0.0
   Implementation-Version: 1.0.0
   Label: helloWorld-1.0.0
   Built-By: builder
   Build-Job: JOB-helloWorld
   Build-Date: 2013-07-19_01:33:52
   Build-Number: 357
   Build-Id: 2013-07-18_18-24-53
   Change: 6ea8a16
"""
        package_query_result = CommandResult(True, response)
        result = parse_command_result(package_query_result)

        assert result['Build-Number'] == '357'
        assert result['Build-Job'] == 'JOB-helloWorld'