def test_elements_path_input(self):
     test_path = '/test/elements/path'
     self.useFixture(
         fixtures.EnvironmentVariable('ELEMENTS_PATH', test_path))
     env = undercloud._generate_environment('.')
     self.assertEqual(test_path, env['ELEMENTS_PATH'])
Exemplo n.º 2
0
 def test_section_from_url(self):
     create_config_from_string('''[example.com]\nfoo=bar''')
     self.useFixture(fixtures.EnvironmentVariable(
         'UBUNTU_SSO_API_ROOT_URL', 'http://example.com/api/v2'))
     conf = config.Config()
     self.assertThat(conf.get('foo'), Equals('bar'))
Exemplo n.º 3
0
 def test_version_from_snap(self):
     self.useFixture(fixtures.EnvironmentVariable("SNAP_NAME", "snapcraft"))
     self.useFixture(fixtures.EnvironmentVariable("SNAP_VERSION", "3.14"))
     self.assertThat(snapcraft._get_version(), Equals("3.14"))
Exemplo n.º 4
0
    def setUp(self):
        """Run before each test method to initialize test environment."""
        super(TestCase, self).setUp()
        self.useFixture(
            nova_fixtures.Timeout(os.environ.get('OS_TEST_TIMEOUT', 0),
                                  self.TIMEOUT_SCALING_FACTOR))

        self.useFixture(fixtures.NestedTempfile())
        self.useFixture(fixtures.TempHomeDir())
        self.useFixture(log_fixture.get_logging_handle_error_fixture())

        self.useFixture(nova_fixtures.OutputStreamCapture())

        self.useFixture(nova_fixtures.StandardLogging())

        # NOTE(sdague): because of the way we were using the lock
        # wrapper we eneded up with a lot of tests that started
        # relying on global external locking being set up for them. We
        # consider all of these to be *bugs*. Tests should not require
        # global external locking, or if they do, they should
        # explicitly set it up themselves.
        #
        # The following REQUIRES_LOCKING class parameter is provided
        # as a bridge to get us there. No new tests should be added
        # that require it, and existing classes and tests should be
        # fixed to not need it.
        if self.REQUIRES_LOCKING:
            lock_path = self.useFixture(fixtures.TempDir()).path
            self.fixture = self.useFixture(
                config_fixture.Config(lockutils.CONF))
            self.fixture.config(lock_path=lock_path, group='oslo_concurrency')

        self.useFixture(conf_fixture.ConfFixture(CONF))
        self.useFixture(nova_fixtures.RPCFixture('nova.test'))

        if self.USES_DB:
            self.useFixture(nova_fixtures.Database())

        # NOTE(blk-u): WarningsFixture must be after the Database fixture
        # because sqlalchemy-migrate messes with the warnings filters.
        self.useFixture(nova_fixtures.WarningsFixture())

        # NOTE(danms): Make sure to reset us back to non-remote objects
        # for each test to avoid interactions. Also, backup the object
        # registry.
        objects_base.NovaObject.indirection_api = None
        self._base_test_obj_backup = copy.copy(
            objects_base.NovaObjectRegistry._registry._obj_classes)
        self.addCleanup(self._restore_obj_registry)

        # NOTE(mnaser): All calls to utils.is_neutron() are cached in
        # nova.utils._IS_NEUTRON.  We set it to None to avoid any
        # caching of that value.
        utils._IS_NEUTRON = None

        mox_fixture = self.useFixture(moxstubout.MoxStubout())
        self.mox = mox_fixture.mox
        self.stubs = mox_fixture.stubs
        self.addCleanup(self._clear_attrs)
        self.useFixture(fixtures.EnvironmentVariable('http_proxy'))
        self.policy = self.useFixture(policy_fixture.PolicyFixture())

        self.useFixture(nova_fixtures.PoisonFunctions())
Exemplo n.º 5
0
    def setUp(self):
        super().setUp()
        if os.getenv("SNAPCRAFT_FROM_SNAP", False):
            self.snapcraft_command = "/snap/bin/snapcraft"
        elif os.getenv("SNAPCRAFT_FROM_DEB", False):
            self.snapcraft_command = "/usr/bin/snapcraft"
            self.snapcraft_parser_command = "/usr/bin/snapcraft-parser"
        elif os.getenv("VIRTUAL_ENV") and sys.platform == "win32":
            self.snapcraft_command = ["python", "-m", "snapcraft.cli.__main__"]
            self.snapcraft_parser_command = os.path.join(
                os.getenv("VIRTUAL_ENV"), "bin", "snapcraft-parser")
        elif os.getenv("VIRTUAL_ENV"):
            self.snapcraft_command = os.path.join(os.getenv("VIRTUAL_ENV"),
                                                  "bin", "snapcraft")
            self.snapcraft_parser_command = os.path.join(
                os.getenv("VIRTUAL_ENV"), "bin", "snapcraft-parser")
        elif os.getenv("SNAPCRAFT_FROM_BREW", False):
            self.snapcraft_command = "/usr/local/bin/snapcraft"
        else:
            raise EnvironmentError(
                "snapcraft is not setup correctly for testing. Either set "
                "SNAPCRAFT_FROM_SNAP, SNAPCRAFT_FROM_DEB or "
                "SNAPCRAFT_FROM_BREW to run from either the snap, deb or "
                "brew, or make sure your venv is properly setup as described "
                "in HACKING.md.")

        if os.getenv("SNAPCRAFT_FROM_SNAP", False):
            self.patchelf_command = "/snap/snapcraft/current/usr/bin/patchelf"
            self.execstack_command = "/snap/snapcraft/current/usr/sbin/execstack"
        else:
            self.patchelf_command = "patchelf"
            self.execstack_command = "execstack"

        self.snaps_dir = os.path.join(os.path.dirname(__file__), "snaps")
        temp_cwd_fixture = fixture_setup.TempCWD()
        self.useFixture(temp_cwd_fixture)
        self.path = temp_cwd_fixture.path

        # Use a separate path for XDG dirs, or changes there may be detected as
        # source changes.
        self.xdg_path = self.useFixture(fixtures.TempDir()).path
        self.useFixture(fixture_setup.TempXDG(self.xdg_path))

        # Use a dumb terminal for tests
        self.useFixture(fixtures.EnvironmentVariable("TERM", "dumb"))

        # Disable Sentry reporting for tests, otherwise they'll hang waiting
        # for input
        self.useFixture(
            fixtures.EnvironmentVariable("SNAPCRAFT_ENABLE_SENTRY", "false"))

        # Note that these directories won't exist when the test starts,
        # they might be created after calling the snapcraft command on the
        # project dir.
        self.parts_dir = "parts"
        self.stage_dir = "stage"
        self.prime_dir = "prime"

        self.deb_arch = platform.get_deb_arch()
        self.arch_triplet = platform.get_arch_triplet()

        self.distro_series = os_release.get_version_codename()
Exemplo n.º 6
0
    def setUp(self):
        super().setUp()
        temp_cwd_fixture = fixture_setup.TempCWD()
        self.useFixture(temp_cwd_fixture)
        self.path = temp_cwd_fixture.path

        # Use a separate path for XDG dirs, or changes there may be detected as
        # source changes.
        self.xdg_path = self.useFixture(fixtures.TempDir()).path
        self.useFixture(fixture_setup.TempXDG(self.xdg_path))
        self.fake_terminal = fixture_setup.FakeTerminal()
        self.useFixture(self.fake_terminal)
        # Some tests will directly or indirectly change the plugindir, which
        # is a module variable. Make sure that it is returned to the original
        # value when a test ends.
        self.addCleanup(common.set_plugindir, common.get_plugindir())
        self.addCleanup(common.set_schemadir, common.get_schemadir())
        self.addCleanup(common.set_extensionsdir, common.get_extensionsdir())
        self.addCleanup(common.set_keyringsdir, common.get_keyringsdir())
        self.addCleanup(common.reset_env)
        common.set_schemadir(os.path.join(get_snapcraft_path(), "schema"))
        self.fake_logger = fixtures.FakeLogger(level=logging.ERROR)
        self.useFixture(self.fake_logger)

        # Some tests will change the apt Dir::Etc::Trusted and
        # Dir::Etc::TrustedParts directories. Make sure they're properly reset.
        self.addCleanup(
            apt.apt_pkg.config.set,
            "Dir::Etc::Trusted",
            apt.apt_pkg.config.find_file("Dir::Etc::Trusted"),
        )
        self.addCleanup(
            apt.apt_pkg.config.set,
            "Dir::Etc::TrustedParts",
            apt.apt_pkg.config.find_file("Dir::Etc::TrustedParts"),
        )

        patcher = mock.patch("os.sched_getaffinity")
        self.cpu_count = patcher.start()
        self.cpu_count.return_value = {1, 2}
        self.addCleanup(patcher.stop)

        # We do not want the paths to affect every test we have.
        patcher = mock.patch("snapcraft.file_utils.get_snap_tool_path",
                             side_effect=lambda x: x)
        patcher.start()
        self.addCleanup(patcher.stop)

        patcher = mock.patch("snapcraft.internal.indicators.ProgressBar",
                             new=SilentProgressBar)
        patcher.start()
        self.addCleanup(patcher.stop)

        # These are what we expect by default
        self.snap_dir = os.path.join(os.getcwd(), "snap")
        self.prime_dir = os.path.join(os.getcwd(), "prime")
        self.stage_dir = os.path.join(os.getcwd(), "stage")
        self.parts_dir = os.path.join(os.getcwd(), "parts")
        self.local_plugins_dir = os.path.join(self.snap_dir, "plugins")

        # Use this host to run through the lifecycle tests
        self.useFixture(
            fixtures.EnvironmentVariable("SNAPCRAFT_BUILD_ENVIRONMENT",
                                         "host"))

        # Make sure snap installation does the right thing
        self.fake_snapd.installed_snaps = [
            dict(name="core20", channel="stable", revision="10"),
            dict(name="core18", channel="stable", revision="10"),
        ]
        self.fake_snapd.snaps_result = [
            dict(name="core20", channel="stable", revision="10"),
            dict(name="core18", channel="stable", revision="10"),
        ]
        self.fake_snapd.find_result = [
            dict(core20=dict(
                channel="stable",
                channels={"latest/stable": dict(confinement="strict")},
            )),
            dict(core18=dict(
                channel="stable",
                channels={"latest/stable": dict(confinement="strict")},
            )),
        ]
        self.fake_snapd.snap_details_func = None

        self.fake_snap_command = fixture_setup.FakeSnapCommand()
        self.useFixture(self.fake_snap_command)

        # Avoid installing patchelf in the tests
        self.useFixture(
            fixtures.EnvironmentVariable("SNAPCRAFT_NO_PATCHELF", "1"))

        # Disable Sentry reporting for tests, otherwise they'll hang waiting
        # for input
        self.useFixture(
            fixtures.EnvironmentVariable("SNAPCRAFT_ENABLE_ERROR_REPORTING",
                                         "false"))

        # Don't let the managed host variable leak into tests
        self.useFixture(fixtures.EnvironmentVariable("SNAPCRAFT_MANAGED_HOST"))

        machine = os.environ.get("SNAPCRAFT_TEST_MOCK_MACHINE", None)
        self.base_environment = fixture_setup.FakeBaseEnvironment(
            machine=machine)
        self.useFixture(self.base_environment)

        # Make sure "SNAPCRAFT_ENABLE_DEVELOPER_DEBUG" is reset between tests
        self.useFixture(
            fixtures.EnvironmentVariable("SNAPCRAFT_ENABLE_DEVELOPER_DEBUG"))
        self.useFixture(fixture_setup.FakeSnapcraftctl())

        # Don't let host SNAPCRAFT_BUILD_INFO variable leak into tests
        self.useFixture(fixtures.EnvironmentVariable("SNAPCRAFT_BUILD_INFO"))
Exemplo n.º 7
0
    def setUp(self):
        """Run before each test method to initialize test environment."""
        super(TestCase, self).setUp()
        self.useFixture(nova_fixtures.Timeout(
            os.environ.get('OS_TEST_TIMEOUT', 0),
            self.TIMEOUT_SCALING_FACTOR))

        self.useFixture(fixtures.NestedTempfile())
        self.useFixture(fixtures.TempHomeDir())
        self.useFixture(log_fixture.get_logging_handle_error_fixture())

        self.output = nova_fixtures.OutputStreamCapture()
        self.useFixture(self.output)

        self.stdlog = nova_fixtures.StandardLogging()
        self.useFixture(self.stdlog)

        # NOTE(sdague): because of the way we were using the lock
        # wrapper we ended up with a lot of tests that started
        # relying on global external locking being set up for them. We
        # consider all of these to be *bugs*. Tests should not require
        # global external locking, or if they do, they should
        # explicitly set it up themselves.
        #
        # The following REQUIRES_LOCKING class parameter is provided
        # as a bridge to get us there. No new tests should be added
        # that require it, and existing classes and tests should be
        # fixed to not need it.
        if self.REQUIRES_LOCKING:
            lock_path = self.useFixture(fixtures.TempDir()).path
            self.fixture = self.useFixture(
                config_fixture.Config(lockutils.CONF))
            self.fixture.config(lock_path=lock_path,
                                group='oslo_concurrency')

        self.useFixture(conf_fixture.ConfFixture(CONF))

        if self.STUB_RPC:
            self.useFixture(nova_fixtures.RPCFixture('nova.test'))

        # we cannot set this in the ConfFixture as oslo only registers the
        # notification opts at the first instantiation of a Notifier that
        # happens only in the RPCFixture
        CONF.set_default('driver', ['test'],
                         group='oslo_messaging_notifications')

        # NOTE(danms): Make sure to reset us back to non-remote objects
        # for each test to avoid interactions. Also, backup the object
        # registry.
        objects_base.NovaObject.indirection_api = None
        self._base_test_obj_backup = copy.copy(
            objects_base.NovaObjectRegistry._registry._obj_classes)
        self.addCleanup(self._restore_obj_registry)
        objects.Service.clear_min_version_cache()

        # NOTE(danms): Reset the cached list of cells
        from nova.compute import api
        api.CELLS = []
        context.CELL_CACHE = {}
        context.CELLS = []

        self.cell_mappings = {}
        self.host_mappings = {}
        # NOTE(danms): If the test claims to want to set up the database
        # itself, then it is responsible for all the mapping stuff too.
        if self.USES_DB:
            # NOTE(danms): Full database setup involves a cell0, cell1,
            # and the relevant mappings.
            self.useFixture(nova_fixtures.Database(database='api'))
            self.useFixture(nova_fixtures.Database(database='placement'))
            self._setup_cells()
            self.useFixture(nova_fixtures.DefaultFlavorsFixture())
        elif not self.USES_DB_SELF:
            # NOTE(danms): If not using the database, we mock out the
            # mapping stuff and effectively collapse everything to a
            # single cell.
            self.useFixture(nova_fixtures.SingleCellSimple())
            self.useFixture(nova_fixtures.DatabasePoisonFixture())

        # NOTE(blk-u): WarningsFixture must be after the Database fixture
        # because sqlalchemy-migrate messes with the warnings filters.
        self.useFixture(nova_fixtures.WarningsFixture())

        self.useFixture(ovo_fixture.StableObjectJsonFixture())

        # NOTE(mnaser): All calls to utils.is_neutron() are cached in
        # nova.utils._IS_NEUTRON.  We set it to None to avoid any
        # caching of that value.
        utils._IS_NEUTRON = None

        # Reset the traits sync and rc cache flags
        def _reset_traits():
            resource_provider._TRAITS_SYNCED = False
        _reset_traits()
        self.addCleanup(_reset_traits)
        resource_provider._RC_CACHE = None
        # Reset the global QEMU version flag.
        images.QEMU_VERSION = None

        mox_fixture = self.useFixture(moxstubout.MoxStubout())
        self.mox = mox_fixture.mox
        self.stubs = mox_fixture.stubs
        self.addCleanup(self._clear_attrs)
        self.useFixture(fixtures.EnvironmentVariable('http_proxy'))
        self.policy = self.useFixture(policy_fixture.PolicyFixture())
        self.placement_policy = self.useFixture(
            policy_fixture.PlacementPolicyFixture())

        self.useFixture(nova_fixtures.PoisonFunctions())

        openstack_driver.DRIVER_CACHE = {}

        self.useFixture(nova_fixtures.ForbidNewLegacyNotificationFixture())

        # NOTE(mikal): make sure we don't load a privsep helper accidentally
        self.useFixture(nova_fixtures.PrivsepNoHelperFixture())
        self.useFixture(mock_fixture.MockAutospecFixture())

        # FIXME(danms): Disable this for all tests by default to avoid breaking
        # any that depend on default/previous ordering
        self.flags(build_failure_weight_multiplier=0.0,
                   group='filter_scheduler')
Exemplo n.º 8
0
 def test_no_envvars(self):
     self.useFixture(fixtures.EnvironmentVariable('NOVA_USERNAME', 'nova'))
     c = config.OpenStackConfig(config_files=[self.cloud_yaml],
                                vendor_files=[self.vendor_yaml])
     self.assertRaises(exceptions.OpenStackConfigException, c.get_one_cloud,
                       'envvars')
Exemplo n.º 9
0
 def setUp(self):
     self.useFixture(fixtures.EnvironmentVariable('TERM', self.term))
     super().setUp()
Exemplo n.º 10
0
    def setUp(self):
        super().setUp()
        for v in ("http_proxy", "https_proxy"):
            self.useFixture(fixtures.EnvironmentVariable(v, getattr(self, v)))

        self.options.nodejs_package_manager = self.package_manager
Exemplo n.º 11
0
 def putenv(self, key, value, raw=False):
     if not raw:
         key = self.env_prefix + "_" + key
     self.env[key] = value
     return self.useFixture(fixtures.EnvironmentVariable(key, value))
Exemplo n.º 12
0
    def test_parts_build_env_ordering_with_deps(self):
        self.make_snapcraft_yaml("""name: test
version: "1"
summary: test
description: test
confinement: strict

parts:
  part1:
    plugin: nil
  part2:
    plugin: nil
    after: [part1]
""")

        self.useFixture(fixtures.EnvironmentVariable('PATH', '/bin'))

        self.maxDiff = None
        paths = [os.path.join(self.stage_dir, 'lib'),
                 os.path.join(self.stage_dir, 'lib',
                              self.arch_triplet),
                 os.path.join(self.stage_dir, 'usr', 'lib'),
                 os.path.join(self.stage_dir, 'usr', 'lib',
                              self.arch_triplet),
                 os.path.join(self.stage_dir, 'include'),
                 os.path.join(self.stage_dir, 'usr', 'include'),
                 os.path.join(self.stage_dir, 'include',
                              self.arch_triplet),
                 os.path.join(self.stage_dir, 'usr', 'include',
                              self.arch_triplet),
                 os.path.join(self.parts_dir, 'part1', 'install',
                              'include'),
                 os.path.join(self.parts_dir, 'part1', 'install',
                              'lib'),
                 os.path.join(self.parts_dir, 'part2', 'install',
                              'include'),
                 os.path.join(self.parts_dir, 'part2', 'install',
                              'lib')]
        for path in paths:
            os.makedirs(path)

        config = project_loader.Config()
        part2 = [part for part in
                 config.parts.all_parts if part.name == 'part2'][0]
        env = config.parts.build_env_for_part(part2)
        env_lines = '\n'.join(['export {}\n'.format(e) for e in env])

        shell_env = {
            'CFLAGS': '-I/user-provided',
            'CXXFLAGS': '-I/user-provided',
            'CPPFLAGS': '-I/user-provided',
            'LDFLAGS': '-L/user-provided',
            'LD_LIBRARY_PATH': '/user-provided',
        }

        def get_envvar(envvar):
            with tempfile.NamedTemporaryFile(mode='w+') as f:
                f.write(env_lines)
                f.write('echo ${}'.format(envvar))
                f.flush()
                output = subprocess.check_output(['/bin/sh', f.name],
                                                 env=shell_env)
            return output.decode(sys.getfilesystemencoding()).strip()

        expected_cflags = (
            '-I/user-provided '
            '-I{parts_dir}/part2/install/include -I{stage_dir}/include '
            '-I{stage_dir}/usr/include '
            '-I{stage_dir}/include/{arch_triplet} '
            '-I{stage_dir}/usr/include/{arch_triplet}'.format(
                parts_dir=self.parts_dir,
                stage_dir=self.stage_dir,
                arch_triplet=self.arch_triplet))
        self.assertEqual(get_envvar('CFLAGS'), expected_cflags)
        self.assertEqual(get_envvar('CXXFLAGS'), expected_cflags)
        self.assertEqual(get_envvar('CPPFLAGS'), expected_cflags)

        self.assertEqual(
            get_envvar('LDFLAGS'),
            '-L/user-provided '
            '-L{parts_dir}/part2/install/lib -L{stage_dir}/lib '
            '-L{stage_dir}/usr/lib -L{stage_dir}/lib/{arch_triplet} '
            '-L{stage_dir}/usr/lib/{arch_triplet}'.format(
                parts_dir=self.parts_dir,
                stage_dir=self.stage_dir,
                arch_triplet=self.arch_triplet))

        self.assertEqual(
            get_envvar('LD_LIBRARY_PATH'),
            '/user-provided:'
            '{parts_dir}/part2/install/lib:'
            '{stage_dir}/lib:'
            '{stage_dir}/usr/lib:'
            '{stage_dir}/lib/{arch_triplet}:'
            '{stage_dir}/usr/lib/{arch_triplet}:'
            '{stage_dir}/lib:'
            '{stage_dir}/usr/lib:'
            '{stage_dir}/lib/{arch_triplet}:'
            '{stage_dir}/usr/lib/{arch_triplet}'.format(
                parts_dir=self.parts_dir,
                stage_dir=self.stage_dir,
                arch_triplet=self.arch_triplet))
Exemplo n.º 13
0
 def test_remove_dib_yum_repo_conf(self):
     self.useFixture(
         fixtures.EnvironmentVariable('DIB_YUM_REPO_CONF', 'rum_yepo.conf'))
     env = undercloud._generate_environment('.')
     self.assertNotIn(env, 'DIB_YUM_REPO_CONF')
Exemplo n.º 14
0
 def test_other_distro(self):
     self.useFixture(fixtures.EnvironmentVariable('NODE_DIST', None))
     self.mock_distro.mock.return_value = ['Gentoo']
     self.assertRaises(RuntimeError, undercloud._generate_environment, '.')
Exemplo n.º 15
0
 def setUp(self):
     super(BaseVolumeTests, self).setUp()
     ver_fixture = fixtures.EnvironmentVariable('OS_VOLUME_API_VERSION',
                                                '2')
     self.useFixture(ver_fixture)
Exemplo n.º 16
0
    def test_parts_build_env_ordering_with_deps(self):
        snapcraft_yaml = dedent("""\
            name: test
            base: core18
            version: "1"
            summary: test
            description: test
            confinement: strict
            grade: stable

            parts:
              part1:
                plugin: nil
              part2:
                plugin: nil
                after: [part1]
        """)

        self.useFixture(fixtures.EnvironmentVariable("PATH", "/bin"))

        arch_triplet = snapcraft.ProjectOptions().arch_triplet
        self.maxDiff = None
        paths = [
            os.path.join(self.stage_dir, "lib"),
            os.path.join(self.stage_dir, "lib", arch_triplet),
            os.path.join(self.stage_dir, "usr", "lib"),
            os.path.join(self.stage_dir, "usr", "lib", arch_triplet),
            os.path.join(self.stage_dir, "include"),
            os.path.join(self.stage_dir, "usr", "include"),
            os.path.join(self.stage_dir, "include", arch_triplet),
            os.path.join(self.stage_dir, "usr", "include", arch_triplet),
            os.path.join(self.parts_dir, "part1", "install", "include"),
            os.path.join(self.parts_dir, "part1", "install", "lib"),
            os.path.join(self.parts_dir, "part2", "install", "include"),
            os.path.join(self.parts_dir, "part2", "install", "lib"),
        ]
        for path in paths:
            os.makedirs(path)

        project_config = self.make_snapcraft_project(snapcraft_yaml)
        part2 = [
            part for part in project_config.parts.all_parts
            if part.name == "part2"
        ][0]
        env = project_config.parts.build_env_for_part(part2)
        env_lines = "\n".join(["export {}\n".format(e) for e in env])

        shell_env = {
            "CFLAGS": "-I/user-provided",
            "CXXFLAGS": "-I/user-provided",
            "CPPFLAGS": "-I/user-provided",
            "LDFLAGS": "-L/user-provided",
            "LD_LIBRARY_PATH": "/user-provided",
        }

        def get_envvar(envvar):
            with tempfile.NamedTemporaryFile(mode="w+") as f:
                f.write(env_lines)
                f.write("echo ${}".format(envvar))
                f.flush()
                output = subprocess.check_output(["/bin/sh", f.name],
                                                 env=shell_env)
            return output.decode(sys.getfilesystemencoding()).strip()

        expected_cflags = (
            "-I/user-provided "
            "-isystem{parts_dir}/part2/install/include -isystem{stage_dir}/include "
            "-isystem{stage_dir}/usr/include "
            "-isystem{stage_dir}/include/{arch_triplet} "
            "-isystem{stage_dir}/usr/include/{arch_triplet}".format(
                parts_dir=self.parts_dir,
                stage_dir=self.stage_dir,
                arch_triplet=project_config.project.arch_triplet,
            ))
        self.assertThat(get_envvar("CFLAGS"), Equals(expected_cflags))
        self.assertThat(get_envvar("CXXFLAGS"), Equals(expected_cflags))
        self.assertThat(get_envvar("CPPFLAGS"), Equals(expected_cflags))

        self.assertThat(
            get_envvar("LDFLAGS"),
            Equals("-L/user-provided "
                   "-L{parts_dir}/part2/install/lib -L{stage_dir}/lib "
                   "-L{stage_dir}/usr/lib -L{stage_dir}/lib/{arch_triplet} "
                   "-L{stage_dir}/usr/lib/{arch_triplet}".format(
                       parts_dir=self.parts_dir,
                       stage_dir=self.stage_dir,
                       arch_triplet=project_config.project.arch_triplet,
                   )),
        )

        self.assertThat(
            get_envvar("LD_LIBRARY_PATH"),
            Equals("/user-provided:"
                   "{parts_dir}/part2/install/lib:"
                   "{stage_dir}/lib:"
                   "{stage_dir}/usr/lib:"
                   "{stage_dir}/lib/{arch_triplet}:"
                   "{stage_dir}/usr/lib/{arch_triplet}".format(
                       parts_dir=self.parts_dir,
                       stage_dir=self.stage_dir,
                       arch_triplet=project_config.project.arch_triplet,
                   )),
        )
Exemplo n.º 17
0
 def setUp(self):
     super(ShellTest, self).setUp()
     for var in self.FAKE_ENV:
         self.useFixture(fixtures.EnvironmentVariable(var,
                                                      self.FAKE_ENV[var]))
Exemplo n.º 18
0
 def setUp(self):
     super().setUp()
     self.useFixture(
         fixtures.EnvironmentVariable('SNAPCRAFT_SETUP_PROXIES', '1'))
Exemplo n.º 19
0
    def setUp(self):
        """Run before each test method to initialize test environment."""
        super(TestCase, self).setUp()
        self.useFixture(
            nova_fixtures.Timeout(os.environ.get('OS_TEST_TIMEOUT', 0),
                                  self.TIMEOUT_SCALING_FACTOR))

        self.useFixture(fixtures.NestedTempfile())
        self.useFixture(fixtures.TempHomeDir())
        self.useFixture(log_fixture.get_logging_handle_error_fixture())

        self.useFixture(nova_fixtures.OutputStreamCapture())

        self.useFixture(nova_fixtures.StandardLogging())

        # NOTE(sdague): because of the way we were using the lock
        # wrapper we ended up with a lot of tests that started
        # relying on global external locking being set up for them. We
        # consider all of these to be *bugs*. Tests should not require
        # global external locking, or if they do, they should
        # explicitly set it up themselves.
        #
        # The following REQUIRES_LOCKING class parameter is provided
        # as a bridge to get us there. No new tests should be added
        # that require it, and existing classes and tests should be
        # fixed to not need it.
        if self.REQUIRES_LOCKING:
            lock_path = self.useFixture(fixtures.TempDir()).path
            self.fixture = self.useFixture(
                config_fixture.Config(lockutils.CONF))
            self.fixture.config(lock_path=lock_path, group='oslo_concurrency')

        self.useFixture(conf_fixture.ConfFixture(CONF))
        self.useFixture(nova_fixtures.RPCFixture('nova.test'))

        # NOTE(danms): Make sure to reset us back to non-remote objects
        # for each test to avoid interactions. Also, backup the object
        # registry.
        objects_base.NovaObject.indirection_api = None
        self._base_test_obj_backup = copy.copy(
            objects_base.NovaObjectRegistry._registry._obj_classes)
        self.addCleanup(self._restore_obj_registry)

        # NOTE(danms): Reset the cached list of cells
        from nova.compute import api
        api.CELLS = []

        self.cell_mappings = {}
        self.host_mappings = {}
        # NOTE(danms): If the test claims to want to set up the database
        # itself, then it is responsible for all the mapping stuff too.
        if self.USES_DB:
            # NOTE(danms): Full database setup involves a cell0, cell1,
            # and the relevant mappings.
            self.useFixture(nova_fixtures.Database(database='api'))
            self._setup_cells()
            self.useFixture(nova_fixtures.DefaultFlavorsFixture())
        elif not self.USES_DB_SELF:
            # NOTE(danms): If not using the database, we mock out the
            # mapping stuff and effectively collapse everything to a
            # single cell.
            self.useFixture(nova_fixtures.SingleCellSimple())
            self.useFixture(nova_fixtures.DatabasePoisonFixture())

        # NOTE(blk-u): WarningsFixture must be after the Database fixture
        # because sqlalchemy-migrate messes with the warnings filters.
        self.useFixture(nova_fixtures.WarningsFixture())

        self.useFixture(ovo_fixture.StableObjectJsonFixture())

        # NOTE(mnaser): All calls to utils.is_neutron() are cached in
        # nova.utils._IS_NEUTRON.  We set it to None to avoid any
        # caching of that value.
        utils._IS_NEUTRON = None

        mox_fixture = self.useFixture(moxstubout.MoxStubout())
        self.mox = mox_fixture.mox
        self.stubs = mox_fixture.stubs
        self.addCleanup(self._clear_attrs)
        self.useFixture(fixtures.EnvironmentVariable('http_proxy'))
        self.policy = self.useFixture(policy_fixture.PolicyFixture())

        self.useFixture(nova_fixtures.PoisonFunctions())

        openstack_driver.DRIVER_CACHE = {}

        self.useFixture(nova_fixtures.ForbidNewLegacyNotificationFixture())
Exemplo n.º 20
0
 def setUp(self):
     super().setUp()
     for v in ('http_proxy', 'https_proxy'):
         self.useFixture(fixtures.EnvironmentVariable(v, getattr(self, v)))
Exemplo n.º 21
0
 def setUp(self):
     super().setUp()
     if os.getenv('SNAPCRAFT_FROM_SNAP', False):
         self.skipTest('The snapcraft-parser is not provided by the snap')
     self.useFixture(fixtures.EnvironmentVariable('TMPDIR', self.path))
Exemplo n.º 22
0
 def test_depends_on_env(self):
     self.useFixture(
         fixtures.EnvironmentVariable('ELEMENTS_PATH', '/foo/bar'))
     self.assertEqual('/foo/bar', element_dependencies._get_elements_dir())
Exemplo n.º 23
0
 def setUp(self):
     super().setUp()
     self.test_store = fixture_setup.TestStore()
     self.useFixture(self.test_store)
     self.useFixture(
         fixtures.EnvironmentVariable("SNAPCRAFT_TEST_INPUT", "1"))
Exemplo n.º 24
0
 def test_env_not_set(self):
     self.useFixture(fixtures.EnvironmentVariable('ELEMENTS_PATH', ''))
     self.assertRaises(Exception, element_dependencies._get_elements_dir,
                       ())
Exemplo n.º 25
0
 def setUp(self):
     super().setUp()
     override_sso = fixtures.EnvironmentVariable(
         'UBUNTU_SSO_API_ROOT_URL', 'http://example.com/api/v2')
     self.useFixture(override_sso)
Exemplo n.º 26
0
    def test_snap(self):
        self.copy_project_to_cwd('assemble')
        self.run_snapcraft('snap')

        snap_file_path = 'assemble_1.0_{}.snap'.format(self.deb_arch)
        self.assertThat(snap_file_path, FileExists())

        binary1_wrapper_path = os.path.join(self.prime_dir,
                                            'command-assemble-bin.wrapper')
        with open('binary1.after', 'r') as file_:
            expected_binary1_wrapper = file_.read()
        self.assertThat(binary1_wrapper_path,
                        FileContains(expected_binary1_wrapper))

        self.useFixture(
            fixtures.EnvironmentVariable(
                'SNAP', os.path.join(os.getcwd(), self.prime_dir)))
        binary_scenarios = (
            ('command-assemble-service.wrapper', 'service-start\n'),
            ('stop-command-assemble-service.wrapper', 'service-stop\n'),
            ('command-assemble-bin.wrapper', 'binary1\n'),
            ('command-binary2.wrapper', 'binary2\n'),
        )
        for binary, expected_output in binary_scenarios:
            output = subprocess.check_output(os.path.join(
                self.prime_dir, binary),
                                             universal_newlines=True)
            self.assertThat(output, Equals(expected_output))

        with testtools.ExpectedException(subprocess.CalledProcessError):
            subprocess.check_output(os.path.join(self.prime_dir, 'bin',
                                                 'not-wrapped'),
                                    stderr=subprocess.STDOUT)

        self.assertThat(
            os.path.join(self.prime_dir, 'bin', 'not-wrapped.wrapper'),
            Not(FileExists()))

        self.assertThat(
            os.path.join(self.prime_dir, 'bin',
                         'command-binary-wrapper-none.wrapper.wrapper'),
            Not(FileExists()))

        # LP: #1750658
        self.assertThat(
            os.path.join(self.prime_dir, 'meta', 'snap.yaml'),
            FileContains(
                dedent("""\
                name: assemble
                version: 1.0
                summary: one line summary
                description: a longer description
                architectures:
                - {}
                confinement: strict
                grade: stable
                apps:
                  assemble-bin:
                    command: command-assemble-bin.wrapper
                  assemble-service:
                    command: command-assemble-service.wrapper
                    daemon: simple
                    stop-command: stop-command-assemble-service.wrapper
                  binary-wrapper-none:
                    command: subdir/binary3
                  binary2:
                    command: command-binary2.wrapper
            """).format(self.deb_arch)))
Exemplo n.º 27
0
 def setUp(self):
     super().setUp()
     self.useFixture(
         fixtures.EnvironmentVariable('SNAPCRAFT_CONTAINER_BUILDS', '1'))
Exemplo n.º 28
0
    def setUp(self):
        """Run before each test method to initialize test environment."""
        # Ensure BaseTestCase's ConfigureLogging fixture is disabled since
        # we're using our own (StandardLogging).
        with fixtures.EnvironmentVariable('OS_LOG_CAPTURE', '0'):
            super(TestCase, self).setUp()

        # How many of which service we've started. {$service-name: $count}
        self._service_fixture_count = collections.defaultdict(int)

        self.useFixture(nova_fixtures.OpenStackSDKFixture())

        self.useFixture(log_fixture.get_logging_handle_error_fixture())

        self.stdlog = self.useFixture(nova_fixtures.StandardLogging())

        # NOTE(sdague): because of the way we were using the lock
        # wrapper we ended up with a lot of tests that started
        # relying on global external locking being set up for them. We
        # consider all of these to be *bugs*. Tests should not require
        # global external locking, or if they do, they should
        # explicitly set it up themselves.
        #
        # The following REQUIRES_LOCKING class parameter is provided
        # as a bridge to get us there. No new tests should be added
        # that require it, and existing classes and tests should be
        # fixed to not need it.
        if self.REQUIRES_LOCKING:
            lock_path = self.useFixture(fixtures.TempDir()).path
            self.fixture = self.useFixture(
                config_fixture.Config(lockutils.CONF))
            self.fixture.config(lock_path=lock_path,
                                group='oslo_concurrency')

        self.useFixture(conf_fixture.ConfFixture(CONF))

        if self.STUB_RPC:
            self.useFixture(nova_fixtures.RPCFixture('nova.test'))

            # we cannot set this in the ConfFixture as oslo only registers the
            # notification opts at the first instantiation of a Notifier that
            # happens only in the RPCFixture
            CONF.set_default('driver', ['test'],
                             group='oslo_messaging_notifications')

        # NOTE(danms): Make sure to reset us back to non-remote objects
        # for each test to avoid interactions. Also, backup the object
        # registry.
        objects_base.NovaObject.indirection_api = None
        self._base_test_obj_backup = copy.copy(
            objects_base.NovaObjectRegistry._registry._obj_classes)
        self.addCleanup(self._restore_obj_registry)
        objects.Service.clear_min_version_cache()

        # NOTE(danms): Reset the cached list of cells
        from nova.compute import api
        api.CELLS = []
        context.CELL_CACHE = {}
        context.CELLS = []

        self.computes = {}
        self.cell_mappings = {}
        self.host_mappings = {}
        # NOTE(danms): If the test claims to want to set up the database
        # itself, then it is responsible for all the mapping stuff too.
        if self.USES_DB:
            # NOTE(danms): Full database setup involves a cell0, cell1,
            # and the relevant mappings.
            self.useFixture(nova_fixtures.Database(database='api'))
            self._setup_cells()
            self.useFixture(nova_fixtures.DefaultFlavorsFixture())
        elif not self.USES_DB_SELF:
            # NOTE(danms): If not using the database, we mock out the
            # mapping stuff and effectively collapse everything to a
            # single cell.
            self.useFixture(nova_fixtures.SingleCellSimple())
            self.useFixture(nova_fixtures.DatabasePoisonFixture())

        # NOTE(blk-u): WarningsFixture must be after the Database fixture
        # because sqlalchemy-migrate messes with the warnings filters.
        self.useFixture(nova_fixtures.WarningsFixture())

        self.useFixture(ovo_fixture.StableObjectJsonFixture())

        # Reset the global QEMU version flag.
        images.QEMU_VERSION = None

        # Reset the compute RPC API globals (mostly the _ROUTER).
        compute_rpcapi.reset_globals()

        self.addCleanup(self._clear_attrs)
        self.useFixture(fixtures.EnvironmentVariable('http_proxy'))
        self.policy = self.useFixture(policy_fixture.PolicyFixture())

        self.useFixture(nova_fixtures.PoisonFunctions())

        self.useFixture(nova_fixtures.ForbidNewLegacyNotificationFixture())

        # NOTE(mikal): make sure we don't load a privsep helper accidentally
        self.useFixture(nova_fixtures.PrivsepNoHelperFixture())
        self.useFixture(mock_fixture.MockAutospecFixture())

        # FIXME(danms): Disable this for all tests by default to avoid breaking
        # any that depend on default/previous ordering
        self.flags(build_failure_weight_multiplier=0.0,
                   group='filter_scheduler')

        # NOTE(melwitt): Reset the cached set of projects
        quota.UID_QFD_POPULATED_CACHE_BY_PROJECT = set()
        quota.UID_QFD_POPULATED_CACHE_ALL = False
Exemplo n.º 29
0
 def setUp(self):
     self.tempdir = self.useFixture(fixtures.TempDir()).path
     os.chdir(self.tempdir)
     self.useFixture(fixtures.EnvironmentVariable("EDITOR", "cat"))
Exemplo n.º 30
0
    def _setUp(self):
        super()._setUp()

        self.core_base_path = self.useFixture(fixtures.TempDir()).path

        binaries_path = os.path.join(get_snapcraft_path(), "tests", "bin",
                                     "elf")

        new_binaries_path = self.useFixture(fixtures.TempDir()).path
        current_path = os.environ.get("PATH")
        new_path = "{}:{}".format(new_binaries_path, current_path)
        self.useFixture(fixtures.EnvironmentVariable("PATH", new_path))

        # Copy strip
        for f in ["strip", "execstack"]:
            shutil.copy(os.path.join(binaries_path, f),
                        os.path.join(new_binaries_path, f))
            os.chmod(os.path.join(new_binaries_path, f), 0o755)

        # Some values in ldd need to be set with core_path
        with open(os.path.join(binaries_path, "ldd")) as rf:
            with open(os.path.join(new_binaries_path, "ldd"), "w") as wf:
                for line in rf.readlines():
                    wf.write(line.replace("{CORE_PATH}", self.core_base_path))
        os.chmod(os.path.join(new_binaries_path, "ldd"), 0o755)

        # Some values in ldd need to be set with core_path
        self.patchelf_path = os.path.join(new_binaries_path, "patchelf")
        with open(os.path.join(binaries_path, "patchelf")) as rf:
            with open(self.patchelf_path, "w") as wf:
                for line in rf.readlines():
                    wf.write(line.replace("{VERSION}", self._patchelf_version))
        os.chmod(os.path.join(new_binaries_path, "patchelf"), 0o755)

        patcher = mock.patch.object(
            elf.ElfFile,
            "_extract_attributes",
            new_callable=lambda: _fake_elffile_extract_attributes,
        )
        patcher.start()
        self.addCleanup(patcher.stop)

        self._elf_files = {
            "fake_elf-2.26":
            elf.ElfFile(path=os.path.join(self.root_path, "fake_elf-2.26")),
            "fake_elf-2.23":
            elf.ElfFile(path=os.path.join(self.root_path, "fake_elf-2.23")),
            "fake_elf-1.1":
            elf.ElfFile(path=os.path.join(self.root_path, "fake_elf-1.1")),
            "fake_elf-static":
            elf.ElfFile(path=os.path.join(self.root_path, "fake_elf-static")),
            "fake_elf-shared-object":
            elf.ElfFile(
                path=os.path.join(self.root_path, "fake_elf-shared-object")),
            "fake_elf-with-host-libraries":
            elf.ElfFile(path=os.path.join(self.root_path,
                                          "fake_elf-with-host-libraries")),
            "fake_elf-bad-ldd":
            elf.ElfFile(path=os.path.join(self.root_path, "fake_elf-bad-ldd")),
            "fake_elf-bad-patchelf":
            elf.ElfFile(
                path=os.path.join(self.root_path, "fake_elf-bad-patchelf")),
            "fake_elf-with-core-libs":
            elf.ElfFile(
                path=os.path.join(self.root_path, "fake_elf-with-core-libs")),
            "fake_elf-with-missing-libs":
            elf.ElfFile(path=os.path.join(self.root_path,
                                          "fake_elf-with-missing-libs")),
            "fake_elf-with-execstack":
            elf.ElfFile(
                path=os.path.join(self.root_path, "fake_elf-with-execstack")),
            "fake_elf-with-bad-execstack":
            elf.ElfFile(path=os.path.join(self.root_path,
                                          "fake_elf-with-bad-execstack")),
            "libc.so.6":
            elf.ElfFile(path=os.path.join(self.root_path, "libc.so.6")),
            "libssl.so.1.0.0":
            elf.ElfFile(path=os.path.join(self.root_path, "libssl.so.1.0.0")),
        }

        for elf_file in self._elf_files.values():
            with open(elf_file.path, "wb") as f:
                f.write(b"\x7fELF")
                if elf_file.path.endswith("fake_elf-bad-patchelf"):
                    f.write(b"nointerpreter")

        self.root_libraries = {
            "foo.so.1": os.path.join(self.root_path, "foo.so.1"),
            "moo.so.2": os.path.join(self.root_path, "non-standard",
                                     "moo.so.2"),
        }

        barsnap_elf = os.path.join(self.core_base_path, "barsnap.so.2")
        elf_list = [*self.root_libraries.values(), barsnap_elf]

        for root_library in elf_list:
            os.makedirs(os.path.dirname(root_library), exist_ok=True)
            with open(root_library, "wb") as f:
                f.write(b"\x7fELF")