def test(self):

    # The commands various compressions should use
    compress_import = {
      constants.IEC_GZIP: "gzip -d",
      constants.IEC_GZIP_FAST: "gzip -d",
      constants.IEC_GZIP_SLOW: "gzip -d",
      constants.IEC_LZOP: "lzop -d",
      }
    compress_export = {
      constants.IEC_GZIP: "gzip -1",
      constants.IEC_GZIP_FAST: "gzip -1",
      constants.IEC_GZIP_SLOW: "gzip",
      constants.IEC_LZOP: "lzop",
      }

    for mode in [constants.IEM_IMPORT, constants.IEM_EXPORT]:
      if mode == constants.IEM_IMPORT:
        compress_dict = compress_import
      elif mode == constants.IEM_EXPORT:
        compress_dict = compress_export

      for compress in constants.IEC_ALL:
        for magic in [None, 10 * "-", "HelloWorld", "J9plh4nFo2",
                      "24A02A81-2264-4B51-A882-A2AB9D85B420"]:
          opts = CmdBuilderConfig(magic=magic, compress=compress)
          builder = impexpd.CommandBuilder(mode, opts, 1, 2, 3)

          magic_cmd = builder._GetMagicCommand()
          dd_cmd = builder._GetDdCommand()

          if magic:
            self.assert_((magic % "M=%s") in magic_cmd)
            self.assert_(("M=%s" % magic) in dd_cmd)
          else:
            self.assertFalse(magic_cmd)

        for host in ["localhost", "198.51.100.4", "192.0.2.99"]:
          for port in [0, 1, 1234, 7856, 45452]:
            for cmd_prefix in [None, "PrefixCommandGoesHere|",
                               "dd if=/dev/hda bs=1048576 |"]:
              for cmd_suffix in [None, "< /some/file/name",
                                 "| dd of=/dev/null"]:
                opts = CmdBuilderConfig(host=host, port=port, compress=compress,
                                        cmd_prefix=cmd_prefix,
                                        cmd_suffix=cmd_suffix)

                builder = impexpd.CommandBuilder(mode, opts, 1, 2, 3)

                # Check complete command
                cmd = builder.GetCommand()
                self.assert_(isinstance(cmd, list))

                if compress != constants.IEC_NONE:
                  self.assert_(CheckCmdWord(cmd, compress_dict[compress]))

                if cmd_prefix is not None:
                  self.assert_(compat.any(cmd_prefix in i for i in cmd))

                if cmd_suffix is not None:
                  self.assert_(compat.any(cmd_suffix in i for i in cmd))

                # Check socat command
                socat_cmd = builder._GetSocatCommand()

                if mode == constants.IEM_IMPORT:
                  ssl_addr = socat_cmd[-2].split(",")
                  self.assert_(("OPENSSL-LISTEN:%s" % port) in ssl_addr)
                elif mode == constants.IEM_EXPORT:
                  ssl_addr = socat_cmd[-1].split(",")
                  self.assert_(("OPENSSL:%s:%s" % (host, port)) in ssl_addr)

                self.assert_("verify=1" in ssl_addr)
dataset/ETHPy150Open ganeti/ganeti/test/py/ganeti.impexpd_unittest.py/TestCommandBuilder.test/swapped operands of `%`