def test_create_from_obj(self):
        """Test whether a meta object is correctly created from a Kibana object"""

        meta = KibanaObjMeta.create_from_obj(DASHBOARD_OBJ)
        self.assertEqual(meta.id, "2e968fe0-b1bb-11e8-8aac-ef7fd4d8cbad")
        self.assertEqual(meta.title, "GitLab Issues")
        self.assertEqual(meta.type, "dashboard")
        self.assertEqual(meta.version, 9)
        self.assertEqual(meta.updated_at, "2019-01-24T13:20:08.902Z")

        meta = KibanaObjMeta.create_from_obj(DASHBOARD_OBJ_NO_UPDATED_AT)
        self.assertEqual(meta.id, "2e968fe0-b1bb-11e8-8aac-ef7fd4d8cbad")
        self.assertEqual(meta.title, "GitLab Issues")
        self.assertEqual(meta.type, "dashboard")
        self.assertEqual(meta.version, 9)
        self.assertIsNone(meta.updated_at)

        with self.assertLogs(logger, level='WARNING') as cm:
            meta = KibanaObjMeta.create_from_obj(DASHBOARD_OBJ_NO_TITLE)
            self.assertEqual(meta.id, "2e968fe0-b1bb-11e8-8aac-ef7fd4d8cbad")
            self.assertIsNone(meta.title)
            self.assertEqual(meta.type, "dashboard")
            self.assertEqual(meta.version, 9)
            self.assertEqual(meta.updated_at, "2019-01-24T13:20:08.902Z")

            self.assertEqual(cm.output[0], "WARNING:archimedes.kibana_obj_meta:Obj dashboard with id "
                                           "2e968fe0-b1bb-11e8-8aac-ef7fd4d8cbad doesn't have a title")
Exemple #2
0
    def test_create_from_obj(self):
        """Test whether a meta object is correctly created from a Kibana object"""

        meta = KibanaObjMeta.create_from_obj(DASHBOARD_OBJ)
        self.assertEqual(meta.id, "2e968fe0-b1bb-11e8-8aac-ef7fd4d8cbad")
        self.assertEqual(meta.title, "GitLab Issues")
        self.assertEqual(meta.type, "dashboard")
        self.assertEqual(meta.version, 9)
        self.assertEqual(meta.updated_at, "2019-01-24T13:20:08.902Z")

        meta = KibanaObjMeta.create_from_obj(DASHBOARD_OBJ_NO_UPDATED_AT)
        self.assertEqual(meta.id, "2e968fe0-b1bb-11e8-8aac-ef7fd4d8cbad")
        self.assertEqual(meta.title, "GitLab Issues")
        self.assertEqual(meta.type, "dashboard")
        self.assertEqual(meta.version, 9)
        self.assertIsNone(meta.updated_at)
    def test_add_alias(self):
        """Test whether an alias is added to the registry"""

        path = os.path.join(self.tmp_path, REGISTRY_NAME)
        copy_content('data/registry_full', path)

        registry = Registry(self.tmp_path)

        tuples = [t for t in registry.find_all()]
        self.assertEqual(len(tuples), 11)

        new_alias = '12'
        new_obj = KibanaObjMeta.create_from_obj(DASHBOARD_OBJ)
        registry.add(new_obj)

        tuples = [t for t in registry.find_all()]
        self.assertEqual(len(tuples), 12)

        alias, meta = registry.find(new_alias)

        self.assertEqual(meta.id, DASHBOARD_OBJ['id'])
        self.assertEqual(meta.title, DASHBOARD_OBJ['attributes']['title'])
        self.assertEqual(meta.type, DASHBOARD_OBJ['type'])
        self.assertEqual(meta.updated_at, DASHBOARD_OBJ['updated_at'])
        self.assertEqual(meta.version, DASHBOARD_OBJ['version'])
Exemple #4
0
    def __find_remote_objs(self):
        """Return the meta information of the Kibana objects stored in Kibana."""

        for obj in self.kibana.find_all():
            if obj['type'] not in [
                    VISUALIZATION, INDEX_PATTERN, SEARCH, DASHBOARD
            ]:
                continue

            meta_obj = KibanaObjMeta.create_from_obj(obj)
            yield meta_obj
    def test_add_alias_duplicated(self):
        """Test whether an exception is thrown when the same object already exists in the registry"""

        path = os.path.join(self.tmp_path, REGISTRY_NAME)
        copy_content('data/registry_slim', path)

        registry = Registry(self.tmp_path)

        new_obj = KibanaObjMeta.create_from_obj(VISUALIZATION_OBJ_DUPLICATED)
        with self.assertRaises(RegistryError):
            registry.add(new_obj)
    def test_repr_no_updated_at(self):
        """Test whether the repr method doesn't fail when updated_at is null"""

        obj = KibanaObjMeta.create_from_obj(DASHBOARD_OBJ_NO_UPDATED_AT)
        str_repr = repr(obj)

        expected = {
            'id': obj.id,
            'type': obj.type,
            'version': obj.version,
            'title': obj.title
        }

        self.assertEqual(str_repr, json.dumps(expected, sort_keys=True, indent=4))
    def test_repr_no_title(self):
        """Test whether the repr method properly works for object without a title"""

        obj = KibanaObjMeta.create_from_obj(DASHBOARD_OBJ_NO_TITLE)
        str_repr = repr(obj)

        expected = {
            'id': obj.id,
            'type': obj.type,
            'version': obj.version,
            'title': obj.title,
            'updated_at': obj.updated_at
        }

        self.assertEqual(str_repr, json.dumps(expected, sort_keys=True, indent=4))
    def test_add_alias_force(self):
        """Test whether an object is overwritten if it already exists in the registry and the param force is on"""

        path = os.path.join(self.tmp_path, REGISTRY_NAME)
        copy_content('data/registry_slim', path)

        registry = Registry(self.tmp_path)

        tuples = [t for t in registry.find_all()]
        self.assertEqual(len(tuples), 2)

        new_obj = KibanaObjMeta.create_from_obj(VISUALIZATION_OBJ_DUPLICATED)
        registry.add(new_obj, force=True)

        tuples = [t for t in registry.find_all()]
        self.assertEqual(len(tuples), 2)
Exemple #9
0
    def __find_local_objs(self):
        """Return the meta information of the Kibana objects stored on disk."""

        for path, obj in self.manager.find_all():
            meta_obj = KibanaObjMeta.create_from_obj(obj)
            yield meta_obj
Exemple #10
0
    def __find_remote_objs(self):
        """Return the meta information of the Kibana objects stored in Kibana."""

        for obj in self.kibana.find_all():
            meta_obj = KibanaObjMeta.create_from_obj(obj)
            yield meta_obj