Beispiel #1
0
 def _run_load_metadata(self, container_id):
     """Load container metadata from container JSON payload"""
     # get container metadata unless we are dealing with a simple directory
     # tree in which case we don't have metadata
     if Config.conf['location']:
         container_dir = ""
         container_json = []
     else:
         container_structure = \
             ContainerStructure(self.localrepo, container_id)
         (container_dir, container_json) = \
             container_structure.get_container_attr()
         if not container_dir:
             return(None, None)
         # load metadata from container
         if not self.opt["nometa"]:
             if not self.opt["user"]:
                 self.opt["user"] = \
                     container_structure.get_container_meta(
                         "User", "", container_json)
             if not self.opt["cwd"]:
                 self.opt["cwd"] = \
                     container_structure.get_container_meta(
                         "WorkingDir", "", container_json)
             if not self.opt["hostname"]:
                 self.opt["hostname"] = \
                     container_structure.get_container_meta(
                         "Hostname", "", container_json)
             if not self.opt["domain"]:
                 self.opt["domain"] = \
                     container_structure.get_container_meta(
                         "Domainname", "", container_json)
             if self.opt["entryp"] is False:
                 self.opt["entryp"] = \
                     container_structure.get_container_meta(
                         "Entrypoint", [], container_json)
                 if not self.opt["cmd"]:
                     self.opt["cmd"] = \
                         container_structure.get_container_meta(
                             "Cmd", [], container_json)
             elif not self.opt["entryp"]:
                 self.opt["entryp"] = []
             else:
                 if isinstance(self.opt["entryp"], str):
                     self.opt["entryp"] = \
                         self.opt["entryp"].strip().split(' ')
             self.opt["Volumes"] = \
                 container_structure.get_container_meta(
                     "Volumes", [], container_json)
             self.opt["portsexp"].extend(
                 container_structure.get_container_meta(
                     "ExposedPorts", [], container_json))
             self.opt["env"].extendif(
                 container_structure.get_container_meta(
                     "Env", [], container_json))
     return(container_dir, container_json)
Beispiel #2
0
    def test_02_get_container_attr(self, mock_msg):
        """Test02 ContainerStructure().get_container_attr()."""
        mock_msg.return_value.level.return_value = 0
        Config().conf['location'] = "/"
        prex = ContainerStructure(self.local)
        (container_dir, container_json) = prex.get_container_attr()
        self.assertEqual(container_dir, "")
        self.assertEqual(container_json, [])

        Config().conf['location'] = ""
        self.local.cd_container.return_value = ""
        prex = ContainerStructure(self.local)
        (container_dir, container_json) = prex.get_container_attr()
        self.assertEqual(container_dir, False)
        self.assertEqual(container_json, False)
        self.assertTrue(mock_msg.return_value.err.called)

        Config().conf['location'] = ""
        self.local.cd_container.return_value = "/"
        self.local.load_json.return_value = []
        prex = ContainerStructure(self.local)
        (container_dir, container_json) = prex.get_container_attr()
        self.assertEqual(container_dir, False)
        self.assertEqual(container_json, False)
        self.assertTrue(mock_msg.return_value.err.called)

        Config().conf['location'] = ""
        self.local.cd_container.return_value = "/"
        self.local.load_json.return_value = [
            "value",
        ]
        prex = ContainerStructure(self.local)
        (container_dir, container_json) = prex.get_container_attr()
        self.assertEqual(container_dir, "/")
        self.assertEqual(container_json, [
            "value",
        ])