def setUp(self):
        super(BaseRealNotification, self).setUp()
        self.CONF = self.useFixture(fixture_config.Config()).conf
        self.setup_messaging(self.CONF, 'nova')

        pipeline_cfg_file = self.setup_pipeline(['instance', 'memory'])
        self.CONF.set_override("pipeline_cfg_file", pipeline_cfg_file)

        self.expected_samples = 2

        self.CONF.set_override("store_events", True, group="notification")
        self.CONF.set_override("disable_non_metric_meters", False,
                               group="notification")
        ev_pipeline = yaml.dump({
            'sources': [{
                'name': 'test_event',
                'events': ['compute.instance.*'],
                'sinks': ['test_sink']
            }],
            'sinks': [{
                'name': 'test_sink',
                'publishers': ['test://']
            }]
        })
        if six.PY3:
            ev_pipeline = ev_pipeline.encode('utf-8')
        self.expected_events = 1
        ev_pipeline_cfg_file = fileutils.write_to_tempfile(
            content=ev_pipeline, prefix="event_pipeline", suffix="yaml")
        self.CONF.set_override("event_pipeline_cfg_file", ev_pipeline_cfg_file)
        self.CONF.set_override(
            "definitions_cfg_file",
            self.path_get('etc/ceilometer/event_definitions.yaml'),
            group='event')
        self.publisher = test_publisher.TestPublisher("")
Beispiel #2
0
    def test_broken_config_load(self, mylog):
        contents = [("---\n"
                     "resources:\n"
                     "  - resource_type: foobar\n"),
                    ("---\n"
                     "resources:\n"
                     "  - resource_type: 0\n"),
                    ("---\n"
                     "resources:\n"
                     "  - sample_types: ['foo', 'bar']\n"),
                    ("---\n"
                     "resources:\n"
                     "  - sample_types: foobar\n"
                     "  - resource_type: foobar\n"),
                    ]

        for content in contents:
            if six.PY3:
                content = content.encode('utf-8')

            temp = fileutils.write_to_tempfile(content=content,
                                               prefix='gnocchi_resources',
                                               suffix='.yaml')
            self.addCleanup(os.remove, temp)
            self.conf.config(filter_service_activity=False,
                             resources_definition_file=temp,
                             group='dispatcher_gnocchi')
            d = gnocchi.GnocchiDispatcher(self.conf.conf)
            self.assertTrue(mylog.error.called)
            self.assertEqual(0, len(d.resources_definition))
Beispiel #3
0
 def test_starting_with_duplication_namespaces(self):
     content = ("[DEFAULT]\n"
                "transport_url = fake://\n"
                "[database]\n"
                "connection=log://localhost\n")
     if six.PY3:
         content = content.encode('utf-8')
     self.tempfile = fileutils.write_to_tempfile(content=content,
                                                 prefix='ceilometer',
                                                 suffix='.conf')
     self.subp = subprocess.Popen(['ceilometer-polling',
                                   "--config-file=%s" % self.tempfile,
                                   "--polling-namespaces",
                                   "compute",
                                   "compute"],
                                  stderr=subprocess.PIPE)
     expected = (b'Duplicated values: [\'compute\', \'compute\'] '
                 b'found in CLI options, auto de-duplicated')
     # NOTE(gordc): polling process won't quit so wait for a bit and check
     start = time.time()
     while time.time() - start < 5:
         output = self.subp.stderr.readline()
         if expected in output:
             break
     else:
         self.fail('Did not detect expected warning: %s' % expected)
    def test_broken_config_load(self):
        contents = [
            ("---\n"
             "resources:\n"
             "  - resource_type: foobar\n"),
            ("---\n"
             "resources:\n"
             "  - resource_type: 0\n"),
            ("---\n"
             "resources:\n"
             "  - sample_types: ['foo', 'bar']\n"),
            ("---\n"
             "resources:\n"
             "  - sample_types: foobar\n"
             "  - resource_type: foobar\n"),
        ]

        for content in contents:
            if six.PY3:
                content = content.encode('utf-8')

            temp = fileutils.write_to_tempfile(content=content,
                                               prefix='gnocchi_resources',
                                               suffix='.yaml')
            self.addCleanup(os.remove, temp)
            self.conf.config(filter_service_activity=False,
                             resources_definition_file=temp,
                             group='dispatcher_gnocchi')
            self.assertRaises(gnocchi.ResourcesDefinitionException,
                              gnocchi.GnocchiDispatcher, self.conf.conf)
Beispiel #5
0
 def test_transit_nets_cfg_invalid_file_format(self):
     self.plugging_driver._cfg_file = fileutils.write_to_tempfile(
         ("""{
             'EDGENAT': {
                 'gateway_ip': '1.109.100.254',
                 'cidr_exposed': '1.109.100.1/24',
                 'segmentation_id': 1066
             }
          }
          {
             'EDGENATBackup': {
                 'gateway_ip': '1.209.200.254',
                 'cidr_exposed': '1.209.200.1/24',
                 'segmentation_id': 1066
             }
          }""").encode('utf-8')
     )
     # TODO(thbachman): couldn't get assertRaises to work here,
     # so used this construct instead
     try:
         # just accessing the member should trigger the exception
         self.plugging_driver.transit_nets_cfg
         self.assertTrue(False)
     except aci_vlan.AciDriverConfigInvalidFileFormat:
         self.assertTrue(True)
     fileutils.delete_if_exists(self.plugging_driver._cfg_file)
Beispiel #6
0
    def test_broken_config_load(self, mylog):
        contents = [("---\n"
                     "resources:\n"
                     "  - resource_type: foobar\n"),
                    ("---\n"
                     "resources:\n"
                     "  - resource_type: 0\n"),
                    ("---\n"
                     "resources:\n"
                     "  - sample_types: ['foo', 'bar']\n"),
                    ("---\n"
                     "resources:\n"
                     "  - sample_types: foobar\n"
                     "  - resource_type: foobar\n"),
                    ]

        for content in contents:
            if six.PY3:
                content = content.encode('utf-8')

            temp = fileutils.write_to_tempfile(content=content,
                                               prefix='gnocchi_resources',
                                               suffix='.yaml')
            self.addCleanup(os.remove, temp)
            url = netutils.urlsplit(
                "gnocchi://?resources_definition_file=" + temp)
            d = gnocchi.GnocchiPublisher(self.conf.conf, url)
            self.assertTrue(mylog.error.called)
            self.assertEqual(0, len(d.resources_definition))
Beispiel #7
0
 def setup_ceilosca_mapping_def_file(self, cfg):
     if six.PY3:
         cfg = cfg.encode('utf-8')
     ceilosca_mapping_file = fileutils.write_to_tempfile(
         content=cfg, prefix='ceilosca_mapping', suffix='yaml')
     self.addCleanup(os.remove, ceilosca_mapping_file)
     return ceilosca_mapping_file
Beispiel #8
0
    def test_compute_checksum_invalid_algorithm(self):
        path = fileutils.write_to_tempfile(self.content)
        self.assertTrue(os.path.exists(path))
        self.check_file_content(self.content, path)

        self.assertRaises(ValueError, fileutils.compute_file_checksum,
                          path, algorithm='foo')
Beispiel #9
0
 def test_starting_with_duplication_namespaces(self):
     content = ("[DEFAULT]\n"
                "transport_url = fake://\n"
                "[database]\n"
                "connection=log://localhost\n")
     if six.PY3:
         content = content.encode('utf-8')
     self.tempfile = fileutils.write_to_tempfile(content=content,
                                                 prefix='ceilometer',
                                                 suffix='.conf')
     self.subp = subprocess.Popen([
         'ceilometer-polling',
         "--config-file=%s" % self.tempfile, "--polling-namespaces",
         "compute", "compute"
     ],
                                  stderr=subprocess.PIPE)
     expected = (b'Duplicated values: [\'compute\', \'compute\'] '
                 b'found in CLI options, auto de-duplicated')
     # NOTE(gordc): polling process won't quit so wait for a bit and check
     start = time.time()
     while time.time() - start < 5:
         output = self.subp.stderr.readline()
         if expected in output:
             break
     else:
         self.fail('Did not detect expected warning: %s' % expected)
Beispiel #10
0
    def test_broken_config_load(self, mylog):
        contents = [
            ("---\n"
             "resources:\n"
             "  - resource_type: foobar\n"),
            ("---\n"
             "resources:\n"
             "  - resource_type: 0\n"),
            ("---\n"
             "resources:\n"
             "  - sample_types: ['foo', 'bar']\n"),
            ("---\n"
             "resources:\n"
             "  - sample_types: foobar\n"
             "  - resource_type: foobar\n"),
        ]

        for content in contents:
            if six.PY3:
                content = content.encode('utf-8')

            temp = fileutils.write_to_tempfile(content=content,
                                               prefix='gnocchi_resources',
                                               suffix='.yaml')
            self.addCleanup(os.remove, temp)
            self.conf.config(filter_service_activity=False,
                             resources_definition_file=temp,
                             group='dispatcher_gnocchi')
            d = gnocchi.GnocchiDispatcher(self.conf.conf)
            self.assertTrue(mylog.error.called)
            self.assertEqual(0, len(d.resources_definition))
Beispiel #11
0
    def test_broken_config_load(self, mylog):
        contents = [("---\n"
                     "resources:\n"
                     "  - resource_type: foobar\n"),
                    ("---\n"
                     "resources:\n"
                     "  - resource_type: 0\n"),
                    ("---\n"
                     "resources:\n"
                     "  - sample_types: ['foo', 'bar']\n"),
                    ("---\n"
                     "resources:\n"
                     "  - sample_types: foobar\n"
                     "  - resource_type: foobar\n"),
                    ]

        for content in contents:
            if six.PY3:
                content = content.encode('utf-8')

            temp = fileutils.write_to_tempfile(content=content,
                                               prefix='gnocchi_resources',
                                               suffix='.yaml')
            self.addCleanup(os.remove, temp)
            url = netutils.urlsplit(
                "gnocchi://?resources_definition_file=" + temp)
            d = gnocchi.GnocchiPublisher(self.conf.conf, url)
            self.assertTrue(mylog.error.called)
            self.assertEqual(0, len(d.resources_definition))
    def test_broken_config_load(self):
        contents = [("---\n"
                     "resources:\n"
                     "  - resource_type: foobar\n"),
                    ("---\n"
                     "resources:\n"
                     "  - resource_type: 0\n"),
                    ("---\n"
                     "resources:\n"
                     "  - sample_types: ['foo', 'bar']\n"),
                    ("---\n"
                     "resources:\n"
                     "  - sample_types: foobar\n"
                     "  - resource_type: foobar\n"),
                    ]

        for content in contents:
            if six.PY3:
                content = content.encode('utf-8')

            temp = fileutils.write_to_tempfile(content=content,
                                               prefix='gnocchi_resources',
                                               suffix='.yaml')
            self.addCleanup(os.remove, temp)
            self.conf.config(filter_service_activity=False,
                             resources_definition_file=temp,
                             group='dispatcher_gnocchi')
            self.assertRaises(gnocchi.ResourcesDefinitionException,
                              gnocchi.GnocchiDispatcher, self.conf.conf)
Beispiel #13
0
 def setUp(self):
     super(BinEvaluatorTestCase, self).setUp()
     content = "[DEFAULT]\n" "rpc_backend=fake\n" "[database]\n" "connection=log://localhost\n"
     if six.PY3:
         content = content.encode("utf-8")
     self.tempfile = fileutils.write_to_tempfile(content=content, prefix="aodh", suffix=".conf")
     self.subp = None
Beispiel #14
0
 def setUp(self):
     super(BinTestCase, self).setUp()
     content = ("[database]\n" "connection=log://localhost\n")
     if six.PY3:
         content = content.encode('utf-8')
     self.tempfile = fileutils.write_to_tempfile(content=content,
                                                 prefix='panko',
                                                 suffix='.conf')
Beispiel #15
0
    def setup_pipeline_file(pipeline):
        if six.PY3:
            pipeline = pipeline.encode('utf-8')

        pipeline_cfg_file = fileutils.write_to_tempfile(content=pipeline,
                                                        prefix="pipeline",
                                                        suffix="yaml")
        return pipeline_cfg_file
    def setup_event_pipeline(self):
        pipeline = yaml.dump({'sources': [], 'sinks': []})
        if six.PY3:
            pipeline = pipeline.encode('utf-8')

        pipeline_cfg_file = fileutils.write_to_tempfile(
            content=pipeline, prefix="event_pipeline", suffix="yaml")
        return pipeline_cfg_file
Beispiel #17
0
 def setUp(self):
     super(BinTestCase, self).setUp()
     content = ("[DEFAULT]\n" "transport_url = fake://\n")
     if six.PY3:
         content = content.encode('utf-8')
     self.tempfile = fileutils.write_to_tempfile(content=content,
                                                 prefix='ceilometer',
                                                 suffix='.conf')
Beispiel #18
0
    def setup_pipeline_file(pipeline):
        if six.PY3:
            pipeline = pipeline.encode('utf-8')

        pipeline_cfg_file = fileutils.write_to_tempfile(content=pipeline,
                                                        prefix="pipeline",
                                                        suffix="yaml")
        return pipeline_cfg_file
Beispiel #19
0
    def setUp(self):
        super(BinSendSampleTestCase, self).setUp()
        pipeline_cfg_file = self.path_get("etc/ceilometer/pipeline.yaml")
        content = "[DEFAULT]\n" "transport_url = fake://\n" "pipeline_cfg_file={0}\n".format(pipeline_cfg_file)
        if six.PY3:
            content = content.encode("utf-8")

        self.tempfile = fileutils.write_to_tempfile(content=content, prefix="ceilometer", suffix=".conf")
Beispiel #20
0
 def setup_pipeline_file(self, pipeline_data):
     if six.PY3:
         pipeline_data = pipeline_data.encode('utf-8')
     pipeline_cfg_file = fileutils.write_to_tempfile(content=pipeline_data,
                                                     prefix="pipeline",
                                                     suffix="yaml")
     self.addCleanup(os.remove, pipeline_cfg_file)
     return pipeline_cfg_file
Beispiel #21
0
 def setUp(self):
     super(BinEvaluatorTestCase, self).setUp()
     content = ("[database]\n" "connection=log://localhost\n")
     content = content.encode('utf-8')
     self.tempfile = fileutils.write_to_tempfile(content=content,
                                                 prefix='aodh',
                                                 suffix='.conf')
     self.subp = None
 def _load_meter_def_file(self, cfg):
     if six.PY3:
         cfg = cfg.encode('utf-8')
     meter_cfg_file = fileutils.write_to_tempfile(content=cfg,
                                                  prefix="meters",
                                                  suffix="yaml")
     self.CONF.set_override('meter_definitions_cfg_file',
                            meter_cfg_file, group='meter')
     self.handler.definitions = self.handler._load_definitions()
Beispiel #23
0
    def run_api(self, content, err_pipe=None):
        if six.PY3:
            content = content.encode("utf-8")

        self.tempfile = fileutils.write_to_tempfile(content=content, prefix="aodh", suffix=".conf")
        if err_pipe:
            return subprocess.Popen(["aodh-api", "--config-file=%s" % self.tempfile], stderr=subprocess.PIPE)
        else:
            return subprocess.Popen(["aodh-api", "--config-file=%s" % self.tempfile])
Beispiel #24
0
    def test_compute_checksum_invalid_algorithm(self):
        path = fileutils.write_to_tempfile(self.content)
        self.assertTrue(os.path.exists(path))
        self.check_file_content(self.content, path)

        self.assertRaises(ValueError,
                          fileutils.compute_file_checksum,
                          path,
                          algorithm='foo')
 def _load_meter_def_file(self, cfg):
     if six.PY3:
         cfg = cfg.encode('utf-8')
     meter_cfg_file = fileutils.write_to_tempfile(content=cfg,
                                                  prefix="meters",
                                                  suffix="yaml")
     self.CONF.set_override('meter_definitions_cfg_file',
                            meter_cfg_file, group='meter')
     self.handler.definitions = self.handler._load_definitions()
Beispiel #26
0
    def test_file_without_path_and_suffix(self):
        res = fileutils.write_to_tempfile(self.content)
        self.assertTrue(os.path.exists(res))

        (basepath, tmpfile) = os.path.split(res)
        self.assertTrue(basepath.startswith(tempfile.gettempdir()))
        self.assertTrue(tmpfile.startswith('tmp'))

        self.check_file_content(res)
Beispiel #27
0
 def setUp(self):
     super(BinTestCase, self).setUp()
     content = ("[DEFAULT]\n"
                "transport_url = fake://\n")
     if six.PY3:
         content = content.encode('utf-8')
     self.tempfile = fileutils.write_to_tempfile(content=content,
                                                 prefix='ceilometer',
                                                 suffix='.conf')
Beispiel #28
0
 def setUp(self):
     super(BinTestCase, self).setUp()
     content = ("[database]\n"
                "connection=log://localhost\n")
     if six.PY3:
         content = content.encode('utf-8')
     self.tempfile = fileutils.write_to_tempfile(content=content,
                                                 prefix='aodh',
                                                 suffix='.conf')
    def test_file_without_path_and_suffix(self):
        res = fileutils.write_to_tempfile(self.content)
        self.assertTrue(os.path.exists(res))

        (basepath, tmpfile) = os.path.split(res)
        self.assertTrue(basepath.startswith(tempfile.gettempdir()))
        self.assertTrue(tmpfile.startswith("tmp"))

        self.check_file_content(res)
Beispiel #30
0
def _sign_assertion(assertion):
    """Sign a SAML assertion.

    This method utilizes ``xmlsec1`` binary and signs SAML assertions in a
    separate process. ``xmlsec1`` cannot read input data from stdin so the
    prepared assertion needs to be serialized and stored in a temporary
    file. This file will be deleted immediately after ``xmlsec1`` returns.
    The signed assertion is redirected to a standard output and read using
    subprocess.PIPE redirection. A ``saml.Assertion`` class is created
    from the signed string again and returned.

    Parameters that are required in the CONF::
    * xmlsec_binary
    * private key file path
    * public key file path
    :return: XML <Assertion> object

    """
    xmlsec_binary = CONF.saml.xmlsec1_binary
    idp_private_key = CONF.saml.keyfile
    idp_public_key = CONF.saml.certfile

    # xmlsec1 --sign --privkey-pem privkey,cert --id-attr:ID <tag> <file>
    certificates = '%(idp_private_key)s,%(idp_public_key)s' % {
        'idp_public_key': idp_public_key,
        'idp_private_key': idp_private_key
    }

    command_list = [xmlsec_binary, '--sign', '--privkey-pem', certificates,
                    '--id-attr:ID', 'Assertion']

    file_path = None
    try:
        # NOTE(gyee): need to make the namespace prefixes explicit so
        # they won't get reassigned when we wrap the assertion into
        # SAML2 response
        file_path = fileutils.write_to_tempfile(assertion.to_string(
            nspair={'saml': saml2.NAMESPACE,
                    'xmldsig': xmldsig.NAMESPACE}))
        command_list.append(file_path)
        stdout = subprocess.check_output(command_list,
                                         stderr=subprocess.STDOUT)
    except Exception as e:
        msg = _LE('Error when signing assertion, reason: %(reason)s')
        msg = msg % {'reason': e}
        if hasattr(e, 'output'):
            msg += ' output: %(output)s' % {'output': e.output}
        LOG.error(msg)
        raise exception.SAMLSigningError(reason=e)
    finally:
        try:
            if file_path:
                os.remove(file_path)
        except OSError:
            pass

    return saml2.create_class_from_xml_string(saml.Assertion, stdout)
Beispiel #31
0
 def _make_app(self):
     content = ('{"default": ""}')
     if six.PY3:
         content = content.encode('utf-8')
     self.tempfile = fileutils.write_to_tempfile(content=content,
                                                 prefix='policy',
                                                 suffix='.json')
     self.CONF.set_override("policy_file", self.tempfile,
                            group='oslo_policy')
     return super(TestAPIUpgradePath, self)._make_app()
    def test_file_with_not_existing_path(self):
        path = '/tmp/testing/test1'
        res = fileutils.write_to_tempfile(self.content, path=path)
        self.assertTrue(os.path.exists(res))
        (basepath, tmpfile) = os.path.split(res)
        self.assertEqual(basepath, path)
        self.assertTrue(tmpfile.startswith('tmp'))

        self.check_file_content(res)
        shutil.rmtree('/tmp/testing')
Beispiel #33
0
    def test_file_with_not_default_prefix(self):
        prefix = 'test'
        res = fileutils.write_to_tempfile(self.content, prefix=prefix)
        self.assertTrue(os.path.exists(res))

        (basepath, tmpfile) = os.path.split(res)
        self.assertTrue(tmpfile.startswith(prefix))
        self.assertTrue(basepath.startswith(tempfile.gettempdir()))

        self.check_file_content(res)
    def test_file_with_not_default_prefix(self):
        prefix = "test"
        res = fileutils.write_to_tempfile(self.content, prefix=prefix)
        self.assertTrue(os.path.exists(res))

        (basepath, tmpfile) = os.path.split(res)
        self.assertTrue(tmpfile.startswith(prefix))
        self.assertTrue(basepath.startswith(tempfile.gettempdir()))

        self.check_file_content(res)
    def test_file_with_not_existing_path(self):
        path = "/tmp/testing/test1"
        res = fileutils.write_to_tempfile(self.content, path=path)
        self.assertTrue(os.path.exists(res))
        (basepath, tmpfile) = os.path.split(res)
        self.assertEqual(basepath, path)
        self.assertTrue(tmpfile.startswith("tmp"))

        self.check_file_content(res)
        shutil.rmtree("/tmp/testing")
Beispiel #36
0
 def _make_app(self):
     content = ('{"default": ""}')
     if six.PY3:
         content = content.encode('utf-8')
     self.tempfile = fileutils.write_to_tempfile(content=content,
                                                 prefix='policy',
                                                 suffix='.json')
     self.CONF.set_override("policy_file", self.tempfile,
                            group='oslo_policy')
     return super(TestAPIUpgradePath, self)._make_app()
Beispiel #37
0
    def start_fixture(self):
        """Set up config."""

        global LOAD_APP_KWARGS

        self.conf = None

        # Determine the database connection.
        db_url = os.environ.get('PIFPAF_URL', "sqlite://").replace(
            "mysql://", "mysql+pymysql://")
        if not db_url:
            raise case.SkipTest('No database connection configured')

        engine = urlparse.urlparse(db_url).scheme
        if engine not in ENGINES:
            raise case.SkipTest('Database engine not supported')

        conf = fixture_config.Config().conf
        self.conf = conf
        self.conf([], project='ceilometer', validate_default_values=True)
        opts.set_defaults(self.conf)
        conf.import_group('api', 'ceilometer.api.controllers.v2.root')

        content = ('{"default": ""}')
        if six.PY3:
            content = content.encode('utf-8')
        self.tempfile = fileutils.write_to_tempfile(content=content,
                                                    prefix='policy',
                                                    suffix='.json')

        conf.set_override("policy_file", self.tempfile,
                          group='oslo_policy')
        conf.set_override(
            'api_paste_config',
            os.path.abspath(
                'ceilometer/tests/functional/gabbi/gabbi_paste.ini')
        )

        # A special pipeline is required to use the direct publisher.
        conf.import_opt('pipeline_cfg_file', 'ceilometer.pipeline')
        conf.set_override('pipeline_cfg_file',
                          'ceilometer/tests/functional/gabbi_pipeline.yaml')

        database_name = '%s-%s' % (db_url, str(uuid.uuid4()))
        conf.set_override('connection', database_name, group='database')
        conf.set_override('metering_connection', '', group='database')
        conf.set_override('event_connection', '', group='database')

        conf.set_override('gnocchi_is_enabled', False, group='api')
        conf.set_override('aodh_is_enabled', False, group='api')
        conf.set_override('panko_is_enabled', False, group='api')

        LOAD_APP_KWARGS = {
            'conf': conf,
        }
 def __setup_meter_def_file(self, cfg):
     if six.PY3:
         cfg = cfg.encode('utf-8')
     meter_cfg_file = fileutils.write_to_tempfile(content=cfg,
                                                  prefix="meters",
                                                  suffix="yaml")
     self.CONF.set_override(
         'meter_definitions_cfg_file',
         meter_cfg_file, group='meter')
     cfg = notifications.setup_meters_config()
     return cfg
Beispiel #39
0
    def setUp(self):
        super(BinSendSampleTestCase, self).setUp()
        pipeline_cfg_file = self.path_get('etc/ceilometer/pipeline.yaml')
        content = ("[DEFAULT]\n"
                   "pipeline_cfg_file={0}\n".format(pipeline_cfg_file))
        if six.PY3:
            content = content.encode('utf-8')

        self.tempfile = fileutils.write_to_tempfile(content=content,
                                                    prefix='ceilometer',
                                                    suffix='.conf')
Beispiel #40
0
 def setUp(self):
     super(BinTestCase, self).setUp()
     content = ("[DEFAULT]\n"
                "rpc_backend=fake\n"
                "[database]\n"
                "connection=log://localhost\n")
     if six.PY3:
         content = content.encode('utf-8')
     self.tempfile = fileutils.write_to_tempfile(content=content,
                                                 prefix='ceilometer',
                                                 suffix='.conf')
Beispiel #41
0
 def __setup_meter_def_file(self, cfg):
     if six.PY3:
         cfg = cfg.encode('utf-8')
     meter_cfg_file = fileutils.write_to_tempfile(content=cfg,
                                                  prefix="snmp",
                                                  suffix="yaml")
     self.conf.set_override(
         'meter_definitions_file',
         meter_cfg_file, group='hardware')
     cfg = generic.setup_meters_config()
     return cfg
 def __setup_meter_def_file(self, cfg):
     if six.PY3:
         cfg = cfg.encode('utf-8')
     meter_cfg_file = fileutils.write_to_tempfile(content=cfg,
                                                  prefix="snmp",
                                                  suffix="yaml")
     self.conf.set_override('meter_definitions_file',
                            meter_cfg_file,
                            group='hardware')
     cfg = generic.setup_meters_config()
     return cfg
Beispiel #43
0
    def test_compute_checksum_default_algorithm(self):
        path = fileutils.write_to_tempfile(self.content)
        self.assertTrue(os.path.exists(path))
        self.check_file_content(self.content, path)

        expected_checksum = hashlib.sha256()
        expected_checksum.update(self.content)

        actual_checksum = fileutils.compute_file_checksum(path)

        self.assertEqual(expected_checksum.hexdigest(), actual_checksum)
 def setUp(self):
     super(BinTestCase, self).setUp()
     content = ("[DEFAULT]\n"
                "rpc_backend=fake\n"
                "[database]\n"
                "connection=log://localhost\n")
     if six.PY3:
         content = content.encode('utf-8')
     self.tempfile = fileutils.write_to_tempfile(content=content,
                                                 prefix='ceilometer',
                                                 suffix='.conf')
Beispiel #45
0
    def test_compute_checksum_default_algorithm(self):
        path = fileutils.write_to_tempfile(self.content)
        self.assertTrue(os.path.exists(path))
        self.check_file_content(self.content, path)

        expected_checksum = hashlib.sha256()
        expected_checksum.update(self.content)

        actual_checksum = fileutils.compute_file_checksum(path)

        self.assertEqual(expected_checksum.hexdigest(), actual_checksum)
    def test_file_with_not_default_suffix(self):
        suffix = ".conf"
        res = fileutils.write_to_tempfile(self.content, suffix=suffix)
        self.assertTrue(os.path.exists(res))

        (basepath, tmpfile) = os.path.split(res)
        self.assertTrue(basepath.startswith(tempfile.gettempdir()))
        self.assertTrue(tmpfile.startswith("tmp"))
        self.assertTrue(tmpfile.endswith(".conf"))

        self.check_file_content(res)
Beispiel #47
0
    def setUp(self):
        super(BinSendSampleTestCase, self).setUp()
        pipeline_cfg_file = self.path_get('etc/ceilometer/pipeline.yaml')
        content = ("[DEFAULT]\n"
                   "pipeline_cfg_file={0}\n".format(pipeline_cfg_file))
        if six.PY3:
            content = content.encode('utf-8')

        self.tempfile = fileutils.write_to_tempfile(content=content,
                                                    prefix='ceilometer',
                                                    suffix='.conf')
Beispiel #48
0
    def test_file_with_not_existing_path(self):
        random_dir = uuid.uuid4().hex
        path = '/tmp/%s/test1' % random_dir
        res = fileutils.write_to_tempfile(self.content, path=path)
        self.assertTrue(os.path.exists(res))
        (basepath, tmpfile) = os.path.split(res)
        self.assertEqual(basepath, path)
        self.assertTrue(tmpfile.startswith('tmp'))

        self.check_file_content(res)
        shutil.rmtree('/tmp/' + random_dir)
Beispiel #49
0
    def test_file_with_not_default_suffix(self):
        suffix = '.conf'
        res = fileutils.write_to_tempfile(self.content, suffix=suffix)
        self.assertTrue(os.path.exists(res))

        (basepath, tmpfile) = os.path.split(res)
        self.assertTrue(basepath.startswith(tempfile.gettempdir()))
        self.assertTrue(tmpfile.startswith('tmp'))
        self.assertTrue(tmpfile.endswith('.conf'))

        self.check_file_content(res)
    def setup_event_pipeline(self):
        pipeline = yaml.dump({
            'sources': [],
            'sinks': []
        })
        if six.PY3:
            pipeline = pipeline.encode('utf-8')

        pipeline_cfg_file = fileutils.write_to_tempfile(
            content=pipeline, prefix="event_pipeline", suffix="yaml")
        return pipeline_cfg_file
Beispiel #51
0
    def test_file_with_not_existing_path(self):
        random_dir = uuid.uuid4().hex
        path = '/tmp/%s/test1' % random_dir
        res = fileutils.write_to_tempfile(self.content, path=path)
        self.assertTrue(os.path.exists(res))
        (basepath, tmpfile) = os.path.split(res)
        self.assertEqual(basepath, path)
        self.assertTrue(tmpfile.startswith('tmp'))

        self.check_file_content(res)
        shutil.rmtree('/tmp/' + random_dir)
 def __setup_meter_def_file(self, cfg):
     if six.PY3:
         cfg = cfg.encode('utf-8')
     meter_cfg_file = fileutils.write_to_tempfile(content=cfg,
                                                  prefix="meters",
                                                  suffix="yaml")
     self.CONF.set_override('meter_definitions_cfg_file',
                            meter_cfg_file,
                            group='meter')
     cfg = notifications.setup_meters_config()
     return cfg
Beispiel #53
0
    def start_fixture(self):
        """Set up config."""

        global LOAD_APP_KWARGS

        self.conf = None

        # Determine the database connection.
        db_url = os.environ.get('PIFPAF_URL',
                                "sqlite://").replace("mysql://",
                                                     "mysql+pymysql://")
        if not db_url:
            raise case.SkipTest('No database connection configured')

        engine = urlparse.urlparse(db_url).scheme
        if engine not in ENGINES:
            raise case.SkipTest('Database engine not supported')

        conf = fixture_config.Config().conf
        self.conf = conf
        self.conf([], project='ceilometer', validate_default_values=True)
        opts.set_defaults(self.conf)
        conf.import_group('api', 'ceilometer.api.controllers.v2.root')

        content = ('{"default": ""}')
        if six.PY3:
            content = content.encode('utf-8')
        self.tempfile = fileutils.write_to_tempfile(content=content,
                                                    prefix='policy',
                                                    suffix='.json')

        conf.set_override("policy_file", self.tempfile, group='oslo_policy')
        conf.set_override(
            'api_paste_config',
            os.path.abspath(
                'ceilometer/tests/functional/gabbi/gabbi_paste.ini'))

        # A special pipeline is required to use the direct publisher.
        conf.import_opt('pipeline_cfg_file', 'ceilometer.pipeline')
        conf.set_override('pipeline_cfg_file',
                          'ceilometer/tests/functional/gabbi_pipeline.yaml')

        database_name = '%s-%s' % (db_url, str(uuid.uuid4()))
        conf.set_override('connection', database_name, group='database')
        conf.set_override('metering_connection', '', group='database')
        conf.set_override('event_connection', '', group='database')

        conf.set_override('gnocchi_is_enabled', False, group='api')
        conf.set_override('aodh_is_enabled', False, group='api')
        conf.set_override('panko_is_enabled', False, group='api')

        LOAD_APP_KWARGS = {
            'conf': conf,
        }
Beispiel #54
0
 def _setup_meter_def_file(self, cfg):
     cfg = cfg.encode('utf-8')
     meter_cfg_file = fileutils.write_to_tempfile(content=cfg,
                                                  prefix="snmp",
                                                  suffix="yaml")
     self.conf.set_override('meter_definitions_file',
                            meter_cfg_file,
                            group='hardware')
     cfg = declarative.load_definitions(
         self.conf, {}, self.conf.hardware.meter_definitions_file)
     return cfg
Beispiel #55
0
 def _setup_meter_def_file(self, cfg):
     if six.PY3:
         cfg = cfg.encode('utf-8')
     meter_cfg_file = fileutils.write_to_tempfile(content=cfg,
                                                  prefix="snmp",
                                                  suffix="yaml")
     self.conf.set_override(
         'meter_definitions_file',
         meter_cfg_file, group='hardware')
     cfg = declarative.load_definitions(
         {}, self.conf.hardware.meter_definitions_file)
     return cfg
 def _make_app(self, enable_acl=False):
     content = ('{"context_is_project": "project_id:%(project_id)s",'
                '"default" : "!",'
                '"telemetry:create_samples": ""}')
     if six.PY3:
         content = content.encode('utf-8')
     self.tempfile = fileutils.write_to_tempfile(content=content,
                                                 prefix='policy',
                                                 suffix='.json')
     self.CONF.set_override("policy_file", self.tempfile,
                            group='oslo_policy')
     return super(TestPostSamples, self)._make_app()
    def test_file_with_not_existing_path_and_not_default_suffix(self):
        suffix = ".txt"
        path = "/tmp/testing/test2"
        res = fileutils.write_to_tempfile(self.content, path=path, suffix=suffix)
        self.assertTrue(os.path.exists(res))
        (basepath, tmpfile) = os.path.split(res)
        self.assertTrue(tmpfile.startswith("tmp"))
        self.assertEqual(basepath, path)
        self.assertTrue(tmpfile.endswith(suffix))

        self.check_file_content(res)
        shutil.rmtree("/tmp/testing")
Beispiel #58
0
    def _make_app(self, conf):
        content = ('{"context_is_admin": "role:admin",'
                   '"telemetry:events:index": "rule:context_is_admin",'
                   '"telemetry:events:show": "rule:context_is_admin"}')
        if six.PY3:
            content = content.encode('utf-8')
        self.tempfile = fileutils.write_to_tempfile(content=content,
                                                    prefix='policy',
                                                    suffix='.json')

        conf.set_override("policy_file", self.tempfile, group='oslo_policy')
        return webtest.TestApp(app.load_app(conf, appname='panko+noauth'))
Beispiel #59
0
    def _make_app(self, conf, enable_acl=False):
        content = ('{"context_is_admin": "role:admin",'
                   '"telemetry:events:index": "rule:context_is_admin",'
                   '"telemetry:events:show": "rule:context_is_admin"}')
        if six.PY3:
            content = content.encode('utf-8')
        self.tempfile = fileutils.write_to_tempfile(content=content,
                                                    prefix='policy',
                                                    suffix='.json')

        self.CONF.set_override("policy_file", self.tempfile,
                               group='oslo_policy')
        return super(TestApiEventAdminRBAC, self)._make_app(conf)
 def _make_app(self, enable_acl=False):
     content = ('{"context_is_project": "project_id:%(project_id)s",'
                '"default" : "!",'
                '"telemetry:create_samples": ""}')
     if six.PY3:
         content = content.encode('utf-8')
     self.tempfile = fileutils.write_to_tempfile(content=content,
                                                 prefix='policy',
                                                 suffix='.json')
     self.CONF.set_override("policy_file",
                            self.tempfile,
                            group='oslo_policy')
     return super(TestPostSamples, self)._make_app()