Exemple #1
0
    def test_file_run(self):
        msg = str(uuid.uuid4())
        _, tmpfilepath = tempfile.mkstemp()
        osf, exefile = tempfile.mkstemp()
        bash_script = """#!/bin/bash
echo $1 > %s
""" % tmpfilepath

        os.close(osf)
        with open(exefile, "w") as fptr:
            fptr.write(bash_script)

        sha256 = hashlib.sha256()
        sha256.update(bash_script.encode())
        actual_checksum = sha256.hexdigest()

        url = "file://%s" % exefile
        # we are now setup for the test
        arguments = {'url': url, 'arguments': [msg],
                     'checksum': actual_checksum}
        plugin = fetch_plugin.load_plugin(
            self.conf_obj, str(uuid.uuid4()),
            {}, "fetch_plugin", arguments)
        result = plugin.run()
        result = result.get_reply_doc()
        self.assertEqual(result['return_code'], 0)
        self.assertTrue(os.path.exists(tmpfilepath))

        with open(tmpfilepath, "r") as fptr:
            data = fptr.read().strip()

        self.assertEqual(data, msg)
Exemple #2
0
    def test_good_fetch_run(self):
        msg = str(uuid.uuid4())
        _, tmpfilepath = tempfile.mkstemp()
        bash_script = """#!/bin/bash
echo $1 > %s
""" % tmpfilepath

        sha256 = hashlib.sha256()
        sha256.update(bash_script.encode())
        actual_checksum = sha256.hexdigest()

        key_name = "fetchtestkey" + str(uuid.uuid4()).split("-")[0]

        k = boto.s3.key.Key(self.bucket)
        k.key = key_name
        k.set_contents_from_string(bash_script, policy='public-read')
        k.make_public()
        url = "http://%s.s3.amazonaws.com/%s" % (self.bucket_name, key_name)
        # we are now setup for the test
        arguments = {'url': url, 'arguments': [msg],
                     'checksum': actual_checksum}
        plugin = fetch_plugin.load_plugin(
            self.conf_obj, str(uuid.uuid4()),
            {}, "fetch_plugin", arguments)
        result = plugin.run()
        result = result.get_reply_doc()
        self.assertEqual(result['return_code'], 0)
        self.assertTrue(os.path.exists(tmpfilepath))

        with open(tmpfilepath, "r") as fptr:
            data = fptr.read().strip()

        self.assertEqual(data, msg)
Exemple #3
0
    def test_bad_checksum(self):
        msg = str(uuid.uuid4())
        _, tmpfilepath = tempfile.mkstemp()
        bash_script = """#!/bin/bash
echo $1 > %s
""" % tmpfilepath

        sha256 = hashlib.sha256()
        # fake a checksum for failure
        sha256.update(str(uuid.uuid4()).encode())
        actual_checksum = sha256.hexdigest()

        key_name = "fetchtestkey" + str(uuid.uuid4()).split("-")[0]

        k = boto.s3.key.Key(self.bucket)
        k.key = key_name
        k.set_contents_from_string(bash_script, policy='public-read')
        k.make_public()
        url = "http://%s.s3.amazonaws.com/%s" % (self.bucket_name, key_name)
        # we are now setup for the test
        arguments = {'url': url, 'arguments': [msg],
                     'checksum': actual_checksum}
        plugin = fetch_plugin.load_plugin(
            self.conf_obj, str(uuid.uuid4()),
            {}, "fetch_plugin", arguments)
        self.assertRaises(AgentPluginOperationException,
                          plugin.run)
Exemple #4
0
    def test_file_run(self):
        msg = str(uuid.uuid4())
        _, tmpfilepath = tempfile.mkstemp()
        osf, exefile = tempfile.mkstemp()
        bash_script = """#!/bin/bash
echo $1 > %s
""" % tmpfilepath

        os.close(osf)
        with open(exefile, "w") as fptr:
            fptr.write(bash_script)

        sha256 = hashlib.sha256()
        sha256.update(bash_script.encode())
        actual_checksum = sha256.hexdigest()

        url = "file://%s" % exefile
        # we are now setup for the test
        arguments = {
            'url': url,
            'arguments': [msg],
            'checksum': actual_checksum
        }
        plugin = fetch_plugin.load_plugin(self.conf_obj, str(uuid.uuid4()), {},
                                          "fetch_plugin", arguments)
        result = plugin.run()
        result = result.get_reply_doc()
        self.assertEqual(result['return_code'], 0)
        self.assertTrue(os.path.exists(tmpfilepath))

        with open(tmpfilepath, "r") as fptr:
            data = fptr.read().strip()

        self.assertEqual(data, msg)
Exemple #5
0
    def test_bad_checksum(self):
        msg = str(uuid.uuid4())
        _, tmpfilepath = tempfile.mkstemp()
        bash_script = """#!/bin/bash
echo $1 > %s
""" % tmpfilepath

        sha256 = hashlib.sha256()
        # fake a checksum for failure
        sha256.update(str(uuid.uuid4()).encode())
        actual_checksum = sha256.hexdigest()

        key_name = "fetchtestkey" + str(uuid.uuid4()).split("-")[0]

        k = boto.s3.key.Key(self.bucket)
        k.key = key_name
        k.set_contents_from_string(bash_script, policy='public-read')
        k.make_public()
        url = "http://%s.s3.amazonaws.com/%s" % (self.bucket_name, key_name)
        # we are now setup for the test
        arguments = {
            'url': url,
            'arguments': [msg],
            'checksum': actual_checksum
        }
        plugin = fetch_plugin.load_plugin(self.conf_obj, str(uuid.uuid4()), {},
                                          "fetch_plugin", arguments)
        self.assertRaises(AgentPluginOperationException, plugin.run)
Exemple #6
0
    def test_good_fetch_run(self):
        msg = str(uuid.uuid4())
        _, tmpfilepath = tempfile.mkstemp()
        bash_script = """#!/bin/bash
echo $1 > %s
""" % tmpfilepath

        sha256 = hashlib.sha256()
        sha256.update(bash_script.encode())
        actual_checksum = sha256.hexdigest()

        key_name = "fetchtestkey" + str(uuid.uuid4()).split("-")[0]

        k = boto.s3.key.Key(self.bucket)
        k.key = key_name
        k.set_contents_from_string(bash_script, policy='public-read')
        k.make_public()
        url = "http://%s.s3.amazonaws.com/%s" % (self.bucket_name, key_name)
        # we are now setup for the test
        arguments = {
            'url': url,
            'arguments': [msg],
            'checksum': actual_checksum
        }
        plugin = fetch_plugin.load_plugin(self.conf_obj, str(uuid.uuid4()), {},
                                          "fetch_plugin", arguments)
        result = plugin.run()
        result = result.get_reply_doc()
        self.assertEqual(result['return_code'], 0)
        self.assertTrue(os.path.exists(tmpfilepath))

        with open(tmpfilepath, "r") as fptr:
            data = fptr.read().strip()

        self.assertEqual(data, msg)
Exemple #7
0
 def test_bad_url(self):
     url = "http://nothere.dell.com/%s" % str(uuid.uuid4())
     # we are now setup for the test
     arguments = {'url': url}
     plugin = fetch_plugin.load_plugin(self.conf_obj, str(uuid.uuid4()), {},
                                       "fetch_plugin", arguments)
     result = plugin.run()
     result = result.get_reply_doc()
     self.assertNotEqual(result['return_code'], 0)
Exemple #8
0
 def test_bad_url(self):
     url = "http://nothere.dell.com/%s" % str(uuid.uuid4())
     # we are now setup for the test
     arguments = {'url': url}
     plugin = fetch_plugin.load_plugin(
         self.conf_obj, str(uuid.uuid4()),
         {}, "fetch_plugin", arguments)
     result = plugin.run()
     result = result.get_reply_doc()
     self.assertNotEqual(result['return_code'], 0)