Ejemplo n.º 1
0
    def test_broker_file_upload__bad_params(self):
        sp = commonl.subpython(
            self.srcdir +
            "/tcf --config-path : -vvv --url %s broker-file-upload"
            % (self.url))
        r = sp.join()
        self.assertNotEqual(
            r, 0,
            msg = sp.output_str + type(self).ttbd_info())

        sp = commonl.subpython(
            self.srcdir +
            "/tcf --config-path : -vvv --url %s broker-file-upload %s"
            % (self.url, self.target_names[0]))
        r = sp.join()
        self.assertNotEqual(
            r, 0,
            msg = sp.output_str + type(self).ttbd_info())

        sp = commonl.subpython(
            self.srcdir +
            "/tcf --config-path : -vvv --url %s broker-file-upload %s /dest/path/file"
            % (self.url, self.target_names[0]))
        r = sp.join()
        self.assertNotEqual(
            r, 0,
            msg = sp.output_str + type(self).ttbd_info())
Ejemplo n.º 2
0
    def test_target_release(self):
        sp = commonl.subpython(
            self.srcdir + "/tcf --config-path : -vvv --url %s acquire %s" \
            % (self.url, self.target_names[0]))
        r = sp.join()
        self.assertEqual(
            r, 0,
            msg = sp.output_str + type(self).ttbd_info())

        sp = commonl.subpython(
            self.srcdir + "/tcf --config-path : -vvv --url %s release %s" \
            % (self.url, self.target_names[0]))
        r = sp.join()
        self.assertEqual(
            r, 0,
            msg = sp.output_str + type(self).ttbd_info())
Ejemplo n.º 3
0
    def test_config_file_target_list(self):
        """
        Access the URL by configuration
        """
        config = tempfile.NamedTemporaryFile(
            prefix = commonl.testing.mkprefix("tcf-config", cls = type(self)),
            suffix = ".py", delete = True)
        config.write("""\
tcfl.config.url_add("%s")
""" \
                     % self.url)
        config.flush()
        config.seek(0)
        sp = commonl.subpython(
            self.srcdir +
            "/tcf --config-path : -vvv --config-path '' --config-file %s list"
            % config.name)
        r = sp.join()
        self.assertEqual(
            r, 0,
            msg = sp.output_str \
            + "tcf-config: ".join(["\n"] + config.readlines()) \
            + type(self).ttbd_info())

        for target_name in self.target_names:
            self.assertRegexpMatches(
                "".join(sp.stdout_lines), re.compile(target_name),
                msg = "exit: target_name '%s' not found\n" % target_name \
                + sp.output_str \
                + "tcf-config: ".join(["\n"] + config.readlines()) \
                + type(self).ttbd_info())
Ejemplo n.º 4
0
def ttbd_start(cmdline, url = None, timeout = 10,
               stdout_name = None, stderr_name = None):
    """
    Start the TTBD daemon
    """
    sp = commonl.subpython(cmdline,
                           stdout_name = stdout_name,
                           stderr_name = stderr_name)
    t = t0 = time.time()
    r = False
    time.sleep(0.5)
    while not r:
        if t - t0 > timeout:
            sp.output()
            sp.terminate_if_alive()
            raise Exception(
                "ttbd not ready after %d seconds: %s\n" % (timeout, cmdline) \
                + sp.output_str)
        if url != None:
            try:
                API_PREFIX = tcfl.ttb_client.rest_target_broker.API_PREFIX
                r = requests.get(url + API_PREFIX + 'validate_session')
                if r.status_code == 200:
                    break
            except requests.ConnectionError as e:
                # FIXME: need to use logger, but it is still not initialized?
                sys.stderr.write("W: %s\n" % e)
        time.sleep(1.5)
        t = time.time()
    # Check for errors in the configuration
    sp.flush()
    for line in sp.stderr:
        if line.startswith("E["):
            raise RuntimeError("ttbd has errors in the log\n" + sp.output())
    return sp
Ejemplo n.º 5
0
    def test_config_bad_url(self):
        """
        Access the URL by configuration
        """

        sp = commonl.subpython(
            self.srcdir
            + "/tcf --config-path : -vvv --url 'bad/.url_343flimy' list")
        r = sp.join()
        self.assertNotEqual(r, 0, msg = sp.output_str)
Ejemplo n.º 6
0
 def test_target_acquire_nonexistant(self):
     sp = commonl.subpython(
         self.srcdir +
         "/tcf --config-path : -vvv --url %s acquire non_existant"
         % self.url)
     sp.join()
     self.assertRegexpMatches(
         sp.output_str,
         "IndexError: target-id 'non_existant': not found$",
         msg = "IndexError not raised by tcf\n" \
         + sp.output_str + type(self).ttbd_info())
Ejemplo n.º 7
0
 def test_target_list(self):
     sp = commonl.subpython(
         self.srcdir + "/tcf --config-path : -vvv --url %s list" % self.url)
     r = sp.join()
     self.assertEqual(
         r, 0,
         msg = sp.output_str + type(self).ttbd_info())
     for target_name in self.target_names:
         self.assertRegexpMatches(
             "".join(sp.stdout_lines), re.compile(target_name),
             msg = "exit: target_name '%s' not found\n" % target_name \
             + sp.output_str + type(self).ttbd_info())
Ejemplo n.º 8
0
    def test_broker_file_upload__simple(self):
        filename = self.ttbd_config.name
        sp = commonl.subpython(
            self.srcdir +
            "/tcf --config-path : -vvv --url %s broker-file-upload %s  dest/file %s"
            % (self.url, self.target_names[0], filename))
        r = sp.join()
        self.assertEqual(
            r, 0,
            msg = sp.output_str + type(self).ttbd_info())
        # Check the file made it to the daemon's file storage (it's in
        # localhost, so we know it is there)
        expected_filename = os.path.normpath("%s/local/dest/file" % (
            self.ttbd_files_dir))
        logging.debug("expected_filename %s", expected_filename)
        if not os.path.isfile(expected_filename):
            self.fail("expected file '%s' not found\n" % expected_filename \
                      + sp.output_str + type(self).ttbd_info())
        if not filecmp.cmp(expected_filename, filename):
            self.fail("uploaded file and original file are different")

        # Check we can list it and it matches the hash
        sp = commonl.subpython(
            self.srcdir + "/tcf --config-path : --url %s broker-file-list %s" \
            % (self.url, self.target_names[0]))
        r = sp.join()
        self.assertEqual(
            r, 0,
            msg = sp.output_str + type(self).ttbd_info())
        for line in sp.stdout_lines:
            listed_filename, hexdigest = line.split(" ", 1)
            if '/dest/file' ==  listed_filename:
                self.assertEqual(
                    hexdigest,
                    commonl.hash_file(hashlib.sha256(),
                                      self.ttbd_config.name).hexdigest())
Ejemplo n.º 9
0
    def test_config_file_bad_url(self):
        """
        Access the URL by configuration
        """
        config = tempfile.NamedTemporaryFile(
            prefix = commonl.testing.mkprefix("tcf-config", cls = type(self)),
            suffix = ".py", delete = True)
        config.write("""\
tcfl.config.url_add("bad/.url_343flimy")
""")
        config.flush()
        config.seek(0)
        sp = commonl.subpython(
            self.srcdir +
            "/tcf --config-path : -vvv --config-path '' --config-file %s list"
            % config.name)
        r = sp.join()
        self.assertEqual(
            r, 1,
            msg = sp.output_str \
            + "tcf-config: ".join(["\n"] + config.readlines()) \
            + type(self).ttbd_info())
Ejemplo n.º 10
0
 def test_no_command(self):
     sp = commonl.subpython(self.srcdir + "/tcf")
     r = sp.join()
     self.assertNotEqual(r, 0, msg = sp.output_str)