Esempio n. 1
0
 def test__filter_list_dict1(self):
     el1 = dict(id=100, name="donald", last="duck", other=dict(category="duck"))
     el2 = dict(id=200, name="donald", last="trump", other=dict(category="human"))
     el3 = dict(id=300, name="donald", last="ronald mac", other=dict(category="clown"))
     data = [el1, el2, el3]
     ret = _utils._filter_list(data, "donald", {"other": {"category": "clown"}})
     self.assertEquals([el3], ret)
Esempio n. 2
0
 def test__filter_list_name_or_id_glob_not_found(self):
     el1 = dict(id=100, name='donald')
     el2 = dict(id=200, name='pluto')
     el3 = dict(id=200, name='pluto-2')
     data = [el1, el2, el3]
     ret = _utils._filter_list(data, 'q*', None)
     self.assertEqual([], ret)
Esempio n. 3
0
 def test__filter_list_name_or_id_glob_not_found(self):
     el1 = dict(id=100, name='donald')
     el2 = dict(id=200, name='pluto')
     el3 = dict(id=200, name='pluto-2')
     data = [el1, el2, el3]
     ret = _utils._filter_list(data, 'q*', None)
     self.assertEqual([], ret)
Esempio n. 4
0
 def test__filter_list_dict2(self):
     el1 = dict(id=100, name="donald", last="duck", other=dict(category="duck", financial=dict(status="poor")))
     el2 = dict(id=200, name="donald", last="trump", other=dict(category="human", financial=dict(status="rich")))
     el3 = dict(
         id=300, name="donald", last="ronald mac", other=dict(category="clown", financial=dict(status="rich"))
     )
     data = [el1, el2, el3]
     ret = _utils._filter_list(data, "donald", {"other": {"financial": {"status": "rich"}}})
     self.assertEquals([el2, el3], ret)
Esempio n. 5
0
 def test__filter_list_dict1(self):
     el1 = dict(id=100, name='donald', last='duck',
                other=dict(category='duck'))
     el2 = dict(id=200, name='donald', last='trump',
                other=dict(category='human'))
     el3 = dict(id=300, name='donald', last='ronald mac',
                other=dict(category='clown'))
     data = [el1, el2, el3]
     ret = _utils._filter_list(
         data, 'donald', {'other': {'category': 'clown'}})
     self.assertEqual([el3], ret)
Esempio n. 6
0
 def test__filter_list_dict1(self):
     el1 = dict(id=100, name='donald', last='duck',
                other=dict(category='duck'))
     el2 = dict(id=200, name='donald', last='trump',
                other=dict(category='human'))
     el3 = dict(id=300, name='donald', last='ronald mac',
                other=dict(category='clown'))
     data = [el1, el2, el3]
     ret = _utils._filter_list(
         data, 'donald', {'other': {'category': 'clown'}})
     self.assertEqual([el3], ret)
Esempio n. 7
0
 def test__filter_list_unicode(self):
     el1 = dict(id=100, name=u'中文', last='duck',
                other=dict(category='duck', financial=dict(status='poor')))
     el2 = dict(id=200, name=u'中文', last='trump',
                other=dict(category='human', financial=dict(status='rich')))
     el3 = dict(id=300, name='donald', last='ronald mac',
                other=dict(category='clown', financial=dict(status='rich')))
     data = [el1, el2, el3]
     ret = _utils._filter_list(
         data, u'中文',
         {'other': {
             'financial': {'status': 'rich'}
         }})
     self.assertEqual([el2], ret)
Esempio n. 8
0
 def test__filter_list_dict2(self):
     el1 = dict(id=100, name='donald', last='duck',
                other=dict(category='duck', financial=dict(status='poor')))
     el2 = dict(id=200, name='donald', last='trump',
                other=dict(category='human', financial=dict(status='rich')))
     el3 = dict(id=300, name='donald', last='ronald mac',
                other=dict(category='clown', financial=dict(status='rich')))
     data = [el1, el2, el3]
     ret = _utils._filter_list(
         data, 'donald',
         {'other': {
             'financial': {'status': 'rich'}
             }})
     self.assertEqual([el2, el3], ret)
Esempio n. 9
0
def search_services(cloud, name_or_id=None, filters=None):
    # pylint: disable=protected-access
    """Search Keystone services ia $OS_INTERFACE.

    It mainly conforms with `Shade
    <https://docs.openstack.org/shade/latest>`_ but allows testing vs
    public endpoints. It's worth mentioning that it doesn't support keystone
    v2.

    :param name_or_id: Name or id of the desired service.
    :param filters: a dict containing additional filters to use. e.g.
                    {'type': 'network'}.

    :returns: a list of ``munch.Munch`` containing the services description

    :raises: ``OpenStackCloudException`` if something goes wrong during the
        openstack API call.
    """
    services = list_services(cloud)
    return _utils._filter_list(services, name_or_id, filters)
Esempio n. 10
0
 def test__filter_list_filter(self):
     el1 = dict(id=100, name='donald', other='duck')
     el2 = dict(id=200, name='donald', other='trump')
     data = [el1, el2]
     ret = _utils._filter_list(data, 'donald', {'other': 'duck'})
     self.assertEquals([el1], ret)
Esempio n. 11
0
 def test__filter_list_name_or_id(self):
     el1 = dict(id=100, name='donald')
     el2 = dict(id=200, name='pluto')
     data = [el1, el2]
     ret = _utils._filter_list(data, 'donald', None)
     self.assertEquals([el1], ret)
Esempio n. 12
0
 def search_hosts(self, name_or_id=None, filters=None, expand=True):
     hosts = self.list_hosts(expand=expand)
     return _utils._filter_list(hosts, name_or_id, filters)
Esempio n. 13
0
 def test__filter_list_name_or_id(self):
     el1 = dict(id=100, name='donald')
     el2 = dict(id=200, name='pluto')
     data = [el1, el2]
     ret = _utils._filter_list(data, 'donald', None)
     self.assertEqual([el1], ret)
Esempio n. 14
0
 def test__filter_list_name_or_id_non_glob_glob(self):
     el1 = dict(id=100, name='donald')
     el2 = dict(id=200, name='pluto[2017-01-10]')
     data = [el1, el2]
     ret = _utils._filter_list(data, 'pluto', None)
     self.assertEqual([], ret)
Esempio n. 15
0
 def test__filter_list_filter_jmespath(self):
     el1 = dict(id=100, name='donald', other='duck')
     el2 = dict(id=200, name='donald', other='trump')
     data = [el1, el2]
     ret = _utils._filter_list(data, 'donald', "[?other == `duck`]")
     self.assertEqual([el1], ret)
Esempio n. 16
0
 def test__filter_list_filter_jmespath(self):
     el1 = dict(id=100, name='donald', other='duck')
     el2 = dict(id=200, name='donald', other='trump')
     data = [el1, el2]
     ret = _utils._filter_list(data, 'donald', "[?other == `duck`]")
     self.assertEqual([el1], ret)
Esempio n. 17
0
 def search_hosts(self, name_or_id=None, filters=None):
     hosts = self.list_hosts()
     return _utils._filter_list(hosts, name_or_id, filters)
Esempio n. 18
0
 def test__filter_list_name_or_id_non_glob_glob(self):
     el1 = dict(id=100, name='donald')
     el2 = dict(id=200, name='pluto[2017-01-10]')
     data = [el1, el2]
     ret = _utils._filter_list(data, 'pluto', None)
     self.assertEqual([], ret)
Esempio n. 19
0
 def test__filter_list_filter(self):
     el1 = dict(id=100, name="donald", other="duck")
     el2 = dict(id=200, name="donald", other="trump")
     data = [el1, el2]
     ret = _utils._filter_list(data, "donald", {"other": "duck"})
     self.assertEquals([el1], ret)
Esempio n. 20
0
 def test__filter_list_name_or_id(self):
     el1 = dict(id=100, name="donald")
     el2 = dict(id=200, name="pluto")
     data = [el1, el2]
     ret = _utils._filter_list(data, "donald", None)
     self.assertEquals([el1], ret)
Esempio n. 21
0
 def search_hosts(self, name_or_id=None, filters=None, expand=True):
     hosts = self.list_hosts(expand=expand)
     return _utils._filter_list(hosts, name_or_id, filters)
Esempio n. 22
0
 def test__filter_list_filter(self):
     el1 = dict(id=100, name='donald', other='duck')
     el2 = dict(id=200, name='donald', other='trump')
     data = [el1, el2]
     ret = _utils._filter_list(data, 'donald', {'other': 'duck'})
     self.assertEqual([el1], ret)