#1275 fixes for mock 2.0
Merged 4 years ago by msuchy. Opened 4 years ago by praiskup.
Unknown source fixes-for-mock-2.0  into  master

@@ -472,7 +472,8 @@

          rlRun "copr-cli build ${NAME_PREFIX}DownloadMockCfgs $HELLO"

          MYTMPDIR=`mktemp -d -p .` && cd $MYTMPDIR

          wget -r -np $BACKEND_URL/results/${NAME_PREFIX}DownloadMockCfgs/$CHROOT/

-         rlRun "find . -type f | grep 'configs/$CHROOT.cfg'" 0

+         rlAssertEquals "check that configs.tar.gz exists" "$(find . -name configs.tar.gz | wc -l)" 1

+         rlRun "tar tf $(find . -name configs.tar.gz) | grep 'configs/$CHROOT.cfg'" 0

          rlRun "find . -type f | grep 'backend.log'" 0

          rlRun "find . -type f | grep 'root.log'" 0

          cd - && rm -r $MYTMPDIR
@@ -496,7 +497,8 @@

          copr-cli build ${NAME_PREFIX}TestBug1444804 $EVIL_HELLO

          MYTMPDIR=`mktemp -d -p .` && cd $MYTMPDIR

          wget -r -np $BACKEND_URL/results/${NAME_PREFIX}TestBug1444804/$CHROOT/

-         rlRun "find . -type f | grep 'configs/$CHROOT.cfg'" 0

+         rlAssertEquals "check that configs.tar.gz exists" "$(find . -name configs.tar.gz | wc -l)" 1

+         rlRun "tar tf $(find . -name configs.tar.gz) | grep 'configs/$CHROOT.cfg'" 0

          rlRun "find . -type f | grep 'backend.log'" 0

          rlRun "find . -type f | grep 'root.log'" 0

          rlRun "find . -type f | grep 'build.log'" 0
@@ -508,7 +510,7 @@

          rlRun -s "copr-cli build ${NAME_PREFIX}BootstrapProject $HELLO --nowait"

          rlRun "parse_build_id"

          rlRun "copr watch-build $BUILD_ID"

-         rlRun "curl $BACKEND_URL/results/${NAME_PREFIX}BootstrapProject/$CHROOT/`printf %08d $BUILD_ID`-hello/configs/child.cfg |grep \"config_opts\['use_bootstrap_container'\] = True\""

+         rlRun "curl $BACKEND_URL/results/${NAME_PREFIX}BootstrapProject/$CHROOT/`printf %08d $BUILD_ID`-hello/configs.tar.gz | tar xz -O '*configs/child.cfg' | grep \"config_opts\['use_bootstrap_container'\] = True\""

          rlRun "copr-cli modify ${NAME_PREFIX}BootstrapProject --use-bootstrap off"

          rlAssertEquals "" `curl --silent ${FRONTEND_URL}/api/coprs/${NAME_PREFIX}BootstrapProject/detail/ |jq '.detail.use_bootstrap_container'` false

  

@@ -51,12 +51,11 @@

          rlRun "copr add-package-scm --name example --clone-url $COPR_HELLO_GIT --method tito ${NAME_PREFIX}PackageScm" 0

          rlRun "copr edit-package-scm --name example --clone-url $COPR_HELLO_GIT --method rpkg ${NAME_PREFIX}PackageScm" 0

          rlRun "copr build-package --name example ${NAME_PREFIX}PackageScm" 0

- 

-         rlRun "copr-cli delete ${NAME_PREFIX}BuildScm"

-         rlRun "copr-cli delete ${NAME_PREFIX}PackageScm"

      rlPhaseEnd

  

      rlPhaseStartCleanup

+         cleanProject "${NAME_PREFIX}BuildScm"

+         cleanProject "${NAME_PREFIX}PackageScm"

      rlPhaseEnd

  rlJournalPrintText

  rlJournalEnd

file modified
+1 -1
@@ -22,7 +22,7 @@

  {%- endif %}

  {%- if repos %}

  

- config_opts['yum.conf'] += \"\"\"

+ config_opts[config_opts['package_manager'] + '.conf'] += \"\"\"

  {%- for repo in repos %}

  

  [{{ repo.id }}]

@@ -44,7 +44,7 @@

              additional=""

  

          return """

- config_opts['yum.conf'] += \"\"\"

+ config_opts[config_opts['package_manager'] + '.conf'] += \"\"\"

  

  [copr_base]

  name="Copr repository"

file modified
+1 -1
@@ -56,7 +56,7 @@

  Requires: %{python}-requests

  Requires: %{python_pfx}-simplejson

  

- Requires: mock

+ Requires: mock >= 2.0

  Requires: git

  Requires: git-svn

  # for the /bin/unbuffer binary

@@ -19,7 +19,6 @@

          self.enable_net = task.get("enable_net")

          self.repos = task.get("repos")

          self.use_bootstrap_container = task.get("use_bootstrap_container")

-         self.pkg_manager_conf = "dnf" if "custom-1" in task.get("chroot") else "yum"

          self.timeout = task.get("timeout", 3600)

          self.with_opts = task.get("with_opts", [])

          self.without_opts = task.get("without_opts", [])
@@ -33,55 +32,50 @@

  

      def run(self):

          open(self.logfile, 'w').close() # truncate logfile

-         configdir = os.path.join(self.resultdir, "configs")

-         self.prepare_configs(configdir)

+         self.prepare_configs()

  

          spec = locate_spec(self.sourcedir)

          shutil.copy(spec, self.resultdir)

          try:

-             self.produce_srpm(spec, self.sourcedir, configdir, self.resultdir)

+             self.produce_srpm(spec, self.sourcedir, self.resultdir)

  

              srpm = locate_srpm(self.resultdir)

-             self.produce_rpm(srpm, configdir, self.resultdir)

+             self.produce_rpm(srpm, self.resultdir)

          finally:

-             self.clean_cache(configdir)

- 

-     def prepare_configs(self, configdir):

-         site_config_path = os.path.join(configdir, "site-defaults.cfg")

-         mock_config_path = os.path.join(configdir, "{0}.cfg".format(self.chroot))

-         child_config_path = os.path.join(configdir, "child.cfg")

+             self.clean_cache()

+             self.archive_configs()

  

+     def prepare_configs(self):

          try:

-             os.makedirs(configdir)

+             os.makedirs(self.configdir)

          except OSError:

              pass

  

-         shutil.copy2("/etc/mock/site-defaults.cfg", site_config_path)

-         shutil.copy2("/etc/mock/{0}.cfg".format(self.chroot), mock_config_path)

-         cfg = self.render_config_template()

-         with open(child_config_path, "w") as child:

-             child.write(cfg)

+         # Copy all the host's configuration files for the reproducibility

+         # purposes (documentation), those files are not used for builds.

+         subprocess.call(['rsync', '-rl', '/etc/mock/', self.configdir])

  

-         return [child_config_path, mock_config_path, site_config_path]

+         # Generate the target mock config file.

+         with open(self.mock_config_file, "w") as child:

+             child.write(self.render_config_template())

  

      def render_config_template(self):

          jinja_env = Environment(loader=FileSystemLoader(CONF_DIRS))

          template = jinja_env.get_template("mock.cfg.j2")

          return template.render(chroot=self.chroot, task_id=self.task_id, buildroot_pkgs=self.buildroot_pkgs,

                                 enable_net=self.enable_net, use_bootstrap_container=self.use_bootstrap_container,

-                                repos=self.repos, pkg_manager_conf=self.pkg_manager_conf,

+                                repos=self.repos,

                                 copr_username=self.copr_username, copr_projectname=self.copr_projectname,

                                 modules=self.enable_modules)

  

-     def produce_srpm(self, spec, sources, configdir, resultdir):

+     def produce_srpm(self, spec, sources, resultdir):

          cmd = MOCK_CALL + [

              "--buildsrpm",

              "--spec", spec,

              "--sources", sources,

-             "--configdir", configdir,

              "--resultdir", resultdir,

              "--uniqueext", get_mock_uniqueext(),

-             "-r", "child"]

+             "-r", self.mock_config_file]

  

          for with_opt in self.with_opts:

              cmd += ["--with", with_opt]
@@ -102,16 +96,28 @@

          if process.returncode != 0:

              raise RuntimeError("Build failed")

  

-     @classmethod

-     def clean_cache(cls, configdir):

+     def clean_cache(self):

          """ Do best effort /var/mock/cache cleanup. """

          cmd = MOCK_CALL + [

-             "--configdir", configdir,

-             "-r", "child",

+             "-r", self.mock_config_file,

              "--scrub", "cache",

          ]

          subprocess.call(cmd) # ignore failure here, if any

  

+     def archive_configs(self):

+         subprocess.call(['tar', '-cz', '--remove-files',

+                          '-C', os.path.dirname(self.configdir),

+                          '-f', os.path.join(self.resultdir, 'configs.tar.gz'),

+                          os.path.basename(self.configdir)])

+ 

+     @property

+     def configdir(self):

+         return os.path.join(self.resultdir, "configs")

+ 

+     @property

+     def mock_config_file(self):

+         return os.path.join(self.configdir, "child.cfg")

+ 

      @property

      def enable_modules(self):

          """ Return the list() of modules to be enabled """
@@ -134,13 +140,12 @@

  

          return enable

  

-     def produce_rpm(self, srpm, configdir, resultdir):

+     def produce_rpm(self, srpm, resultdir):

          cmd = MOCK_CALL + [

                 "--rebuild", srpm,

-                "--configdir", configdir,

                 "--resultdir", resultdir,

                 "--uniqueext", get_mock_uniqueext(),

-                "-r", "child"]

+                "-r", self.mock_config_file]

  

          for with_opt in self.with_opts:

              cmd += ["--with", with_opt]

@@ -3,4 +3,5 @@

  config_opts['use_host_resolv'] = True

  config_opts['chroot_additional_packages'] = 'make dnf'

  config_opts['plugin_conf']['bind_mount_enable'] = True

+ config_opts['use_bootstrap'] = False

  config_opts['nspawn_args'] = ['--drop-capability=CAP_SYS_ADMIN,CAP_IPC_OWNER,CAP_KILL,CAP_LEASE,CAP_LINUX_IMMUTABLE,CAP_NET_BIND_SERVICE,CAP_NET_BROADCAST,CAP_NET_RAW,CAP_SETGID,CAP_SETPCAP,CAP_SETUID,CAP_SYS_CHROOT,CAP_SYS_NICE,CAP_SYS_PTRACE,CAP_SYS_TTY_CONFIG,CAP_SYS_RESOURCE,CAP_SYS_BOOT,CAP_AUDIT_WRITE,CAP_AUDIT_CONTROL']

file modified
+2 -2
@@ -16,7 +16,7 @@

  

  config_opts['macros']['%copr_username'] = '{{ copr_username }}'

  config_opts['macros']['%copr_projectname'] = '{{ copr_projectname }}'

- config_opts['use_bootstrap_container'] = {{ 'True' if use_bootstrap_container else 'False' }}

+ config_opts['use_bootstrap'] = {{ 'True' if use_bootstrap_container else 'False' }}

  

  {% if use_bootstrap_container %}

  config_opts['bootstrap_chroot_additional_packages'] = []
@@ -27,7 +27,7 @@

  config_opts["module_enable"] += ["{{ module }}"]

  {%- endfor %}

  {% if repos %}

- config_opts['{{ pkg_manager_conf }}.conf'] += """

+ config_opts[f"{config_opts.package_manager}.conf"] += """

  {% for repo in repos %}

  [{{ repo["id"] }}]

  name='{{ repo["name"] }}'

file modified
+26 -26
@@ -80,15 +80,15 @@

          self.child_config = os.path.join(self.configdir, 'child.cfg')

  

          self.mock_rpm_call = [

-             'unbuffer', 'mock', '--rebuild', 'srpm', '--configdir',

-             self.configdir, '--resultdir', self.resultdir,

-             '--uniqueext', '0', '-r', 'child']

+             'unbuffer', 'mock', '--rebuild', 'srpm',

+             '--resultdir', self.resultdir, '--uniqueext', '0',

+             '-r', self.child_config,

+         ]

  

          self.mock_srpm_call = [

              'unbuffer', 'mock', '--buildsrpm', '--spec', 'spec', '--sources',

-             self.sourcedir, '--configdir', self.configdir,

-             '--resultdir', self.resultdir, '--uniqueext', '0', '-r',

-             'child']

+             self.sourcedir, '--resultdir', self.resultdir, '--uniqueext', '0',

+             '-r', self.child_config]

  

          self.config = configparser.RawConfigParser()

          self.config.add_section('main')
@@ -124,12 +124,13 @@

          assert config_opts["root"] == "10-fedora-24-x86_64"

          assert config_opts["chroot_additional_packages"] == "pkg1 pkg2 pkg3"

          assert config_opts["rpmbuild_networking"]

-         assert not config_opts["use_bootstrap_container"]

+         assert not config_opts["use_bootstrap"]

          assert config_opts["macros"]["%copr_username"] == "@copr"

          assert config_opts["macros"]["%copr_projectname"] == "copr-dev"

          assert config_opts["yum.conf"] == []

  

-     def test_mock_config(self, f_mock_calls):

+     @mock.patch("copr_rpmbuild.builders.mock.subprocess.call")

+     def test_mock_config(self, call, f_mock_calls):

          """ test that no module_enable statements are in config """

          MockBuilder(self.task, self.sourcedir, self.resultdir,

                      self.config).run()
@@ -152,13 +153,15 @@

  

  config_opts['macros']['%copr_username'] = '@copr'

  config_opts['macros']['%copr_projectname'] = 'copr-dev'

- config_opts['use_bootstrap_container'] = False

+ config_opts['use_bootstrap'] = False

  

  

  

  """  # TODO: make the output nicer

  

-     def test_mock_options(self, f_mock_calls):

+     @mock.patch("copr_rpmbuild.builders.mock.MockBuilder.prepare_configs")

+     @mock.patch("copr_rpmbuild.builders.mock.MockBuilder.archive_configs")

+     def test_mock_options(self, archive_configs, prep_configs, f_mock_calls):

          """ test that mock options are correctly constructed """

          MockBuilder(self.task, self.sourcedir, self.resultdir,

                      self.config).run()
@@ -170,20 +173,20 @@

          call = f_mock_calls[1]

          assert call[0][0] == self.mock_rpm_call

  

+     @mock.patch("copr_rpmbuild.builders.mock.MockBuilder.prepare_configs")

      @mock.patch("copr_rpmbuild.builders.mock.get_mock_uniqueext")

      @mock.patch("copr_rpmbuild.builders.mock.GentlyTimeoutedPopen")

-     def test_produce_rpm(self, popen_mock, get_mock_uniqueext_mock):

+     def test_produce_rpm(self, popen_mock, get_mock_uniqueext_mock, prep_configs):

          builder = MockBuilder(self.task, self.sourcedir, self.resultdir, self.config)

          get_mock_uniqueext_mock.return_value = '2'

          process = mock.MagicMock(returncode=0)

          popen_mock.return_value = process

-         builder.produce_rpm("/path/to/pkg.src.rpm", "/path/to/configs", "/path/to/results")

+         builder.produce_rpm("/path/to/pkg.src.rpm", "/path/to/results")

          assert_cmd = ['unbuffer', 'mock',

                        '--rebuild', '/path/to/pkg.src.rpm',

-                       '--configdir', '/path/to/configs',

                        '--resultdir', '/path/to/results',

                        '--uniqueext', '2',

-                       '-r', 'child']

+                       '-r', builder.mock_config_file]

          popen_mock.assert_called_with(assert_cmd, stdin=subprocess.PIPE,

                                        timeout=21600)

  
@@ -194,12 +197,6 @@

          success = os.path.join(self.resultdir, "success")

          mock_open.assert_called_with(success, "w")

  

-     def test_custom1_chroot_settings(self):

-         b1 = MockBuilder(self.task, self.sourcedir, self.resultdir, self.config)

-         b2 = MockBuilder(dict(self.task, **{"chroot": "custom-1-x86_64"}), self.sourcedir, self.resultdir, self.config)

-         assert b1.pkg_manager_conf == "yum"

-         assert b2.pkg_manager_conf == "dnf"

- 

      @pytest.mark.parametrize('modules', [

          ['postgresql:9.6'],

          ['moduleA:S1', 'moduleA:S2'],
@@ -211,8 +208,10 @@

          self.task['modules'] = {

              'toggle': [{'enable': x} for x in modules],

          }

-         MockBuilder(self.task, self.sourcedir, self.resultdir,

-                     self.config).run()

+ 

+         with mock.patch("copr_rpmbuild.builders.mock.subprocess.call"):

+             MockBuilder(self.task, self.sourcedir, self.resultdir,

+                         self.config).run()

  

          assert len(f_mock_calls) == 2 # srpm + rpm

  
@@ -224,7 +223,7 @@

          assert call[0][0] == self.mock_rpm_call

  

          part_of_expected_output = (

-             "config_opts['use_bootstrap_container'] = False\n"

+             "config_opts['use_bootstrap'] = False\n"

              "\n"

              "\n"

              "\n"
@@ -247,6 +246,7 @@

      def test_module_mock_assertions(self, f_mock_calls, modules):

          'test that assertions work'

          self.task['modules'] = modules

-         with pytest.raises(AssertionError):

-             MockBuilder(self.task, self.sourcedir, self.resultdir,

-                         self.config).run()

+         with mock.patch("copr_rpmbuild.builders.mock.subprocess.call"):

+             with pytest.raises(AssertionError):

+                 MockBuilder(self.task, self.sourcedir, self.resultdir,

+                             self.config).run()

no initial comment

rebased onto 0df4a4b494300c04755fd6a282345b5c2e6e5045

4 years ago

Thanks for the review, but it doesn't work at least because of this:
--bind=/tmp/mock-resolv.j0_uwp4b:/etc/resolv.conf (nspawn args in generated config).

4 new commits added

  • rpmbuild: copy all mock config, and use child.cfg again
  • rpmbuild: generate self-standing chroot.cfg
  • cli: fix `copr mock-config` to use `dnf.conf/yum.conf` automatically
  • rpmbuild: use dnf.conf/yum.conf automatically
4 years ago

1 new commit added

  • rpmbuild: archive the set of mock configs
4 years ago

rebased onto 4511d92

4 years ago

please take another look, does this make sense?

2 new commits added

  • beaker-tests: expect configs.tar.gz, not child.cfg in resultsdir
  • beaker-tests: use our standard "cleanup" pattern in scm.sh
4 years ago

7 new commits added

  • beaker-tests: expect configs.tar.gz, not child.cfg in resultsdir
  • beaker-tests: use our standard "cleanup" pattern in scm.sh
  • rpmbuild: archive the set of mock configs
  • rpmbuild: copy all mock config, and use child.cfg again
  • rpmbuild: generate self-standing chroot.cfg
  • cli: fix `copr mock-config` to use `dnf.conf/yum.conf` automatically
  • rpmbuild: use dnf.conf/yum.conf automatically
4 years ago

7 new commits added

  • beaker-tests: expect configs.tar.gz, not child.cfg in resultsdir
  • beaker-tests: use our standard "cleanup" pattern in scm.sh
  • rpmbuild: archive the set of mock configs
  • rpmbuild: copy all mock config, and use child.cfg again
  • rpmbuild: generate self-standing chroot.cfg
  • cli: fix `copr mock-config` to use `dnf.conf/yum.conf` automatically
  • rpmbuild: use dnf.conf/yum.conf automatically
4 years ago

1 new commit added

  • rpmbuild: disable bootstrap chroot for make_srpm method
4 years ago

1 new commit added

  • rpmbuild: mock config s/use_bootstrap_container/use_bootstrap/
4 years ago

9 new commits added

  • rpmbuild: mock config s/use_bootstrap_container/use_bootstrap/
  • rpmbuild: disable bootstrap chroot for make_srpm method
  • beaker-tests: expect configs.tar.gz, not child.cfg in resultsdir
  • beaker-tests: use our standard "cleanup" pattern in scm.sh
  • rpmbuild: archive the set of mock configs
  • rpmbuild: copy all mock config, and use child.cfg again
  • rpmbuild: generate self-standing chroot.cfg
  • cli: fix `copr mock-config` to use `dnf.conf/yum.conf` automatically
  • rpmbuild: use dnf.conf/yum.conf automatically
4 years ago

Pull-Request has been merged by msuchy

4 years ago
Metadata