Esempio n. 1
0
    def test_search_for_hosts_by_composed_queries(self):
        """Create one host and test composed queries."""

        db_api.host_create(_get_fake_host_values(mem=8192))
        self.assertEqual(
            1,
            len(
                db_api.host_get_all_by_queries(
                    ['memory_mb > 2048', 'cpu_info like %Westmere%'])))
        self.assertEqual(
            0,
            len(
                db_api.host_get_all_by_queries(
                    ['memory_mb < 2048', 'cpu_info like %Westmere%'])))
        self.assertRaises(db_exceptions.ClimateDBInvalidFilter,
                          db_api.host_get_all_by_queries, ['memory_mb <'])
        self.assertRaises(db_exceptions.ClimateDBNotFound,
                          db_api.host_get_all_by_queries, ['apples < 2048'])
        self.assertRaises(db_exceptions.ClimateDBInvalidFilterOperator,
                          db_api.host_get_all_by_queries,
                          ['memory_mb wrongop 2048'])
        self.assertEqual(
            1, len(db_api.host_get_all_by_queries(['memory_mb in 4096,8192'])))
        self.assertEqual(
            1, len(db_api.host_get_all_by_queries(['memory_mb != null'])))
Esempio n. 2
0
    def test_search_for_hosts_by_cpu_info(self):
        """Create one host and search within cpu_info."""

        db_api.host_create(_get_fake_host_values())
        self.assertEqual(
            1,
            len(db_api.host_get_all_by_queries(['cpu_info like %Westmere%'])))
Esempio n. 3
0
 def test_search_for_hosts_by_ram(self):
     """Create two hosts and check that we can find a host per its RAM info.
     """
     db_api.host_create(_get_fake_host_values(id=1, mem=2048))
     db_api.host_create(_get_fake_host_values(id=2, mem=4096))
     self.assertEqual(2, len(db_api.host_get_all_by_queries(["memory_mb >= 2048"])))
     self.assertEqual(0, len(db_api.host_get_all_by_queries(["memory_mb lt 2048"])))
Esempio n. 4
0
 def test_create_duplicated_host(self):
     """Create a duplicated host and verify that an exception is raised."""
     db_api.host_create(_get_fake_host_values(id='1'))
     # Making sure we still raise a DuplicateDBEntry
     self.assertRaises(db_exceptions.ClimateDBDuplicateEntry,
                       db_api.host_create,
                       _get_fake_host_values(id='1'))
Esempio n. 5
0
    def test_search_for_hosts_by_composed_queries(self):
        """Create one host and test composed queries."""

        db_api.host_create(_get_fake_host_values(mem=8192))
        self.assertEqual(1, len(db_api.host_get_all_by_queries(["memory_mb > 2048", "cpu_info like %Westmere%"])))
        self.assertEqual(0, len(db_api.host_get_all_by_queries(["memory_mb < 2048", "cpu_info like %Westmere%"])))
        self.assertRaises(RuntimeError, db_api.host_get_all_by_queries, ["memory_mb <"])
        self.assertRaises(RuntimeError, db_api.host_get_all_by_queries, ["apples < 2048"])
        self.assertRaises(RuntimeError, db_api.host_get_all_by_queries, ["memory_mb wrongop 2048"])
        self.assertEqual(1, len(db_api.host_get_all_by_queries(["memory_mb in 4096,8192"])))
        self.assertEqual(1, len(db_api.host_get_all_by_queries(["memory_mb != null"])))
Esempio n. 6
0
    def test_search_for_hosts_by_ram(self):
        """Check RAM info search

        Create two hosts and check that we can find a host per its RAM
        info.
        """
        db_api.host_create(_get_fake_host_values(id=1, mem=2048))
        db_api.host_create(_get_fake_host_values(id=2, mem=4096))
        self.assertEqual(
            2, len(db_api.host_get_all_by_queries(['memory_mb >= 2048'])))
        self.assertEqual(
            0, len(db_api.host_get_all_by_queries(['memory_mb lt 2048'])))
Esempio n. 7
0
 def test_search_for_hosts_by_extra_capability(self):
     """Create one host and test extra capability queries."""
     db_api.host_create(_get_fake_host_values(id=1))
     db_api.host_extra_capability_create(
         _get_fake_host_extra_capabilities(computehost_id=1))
     self.assertEqual(1, len(
         db_api.host_get_all_by_queries(['vgpu == 2'])))
     self.assertEqual(0, len(
         db_api.host_get_all_by_queries(['vgpu != 2'])))
     self.assertEqual(1, len(
         db_api.host_get_all_by_queries(['cpu_info like %Westmere%',
                                         'vgpu == 2'])))
     self.assertEqual(0, len(
         db_api.host_get_all_by_queries(['cpu_info like %wrongcpu%',
                                         'vgpu == 2'])))
     self.assertRaises(db_exceptions.ClimateDBNotFound,
                       db_api.host_get_all_by_queries, ['apples < 2048'])
Esempio n. 8
0
 def test_create_host(self):
     """Create a host and verify that all tables
     have been populated.
     """
     result = db_api.host_create(_get_fake_host_values(id="1"))
     self.assertEqual(result["id"], _get_fake_host_values(id="1")["id"])
     # Making sure we still raise a DuplicateDBEntry
     self.assertRaises(RuntimeError, db_api.host_create, _get_fake_host_values(id="1"))
Esempio n. 9
0
 def test_search_for_hosts_by_extra_capability(self):
     """Create one host and test extra capability queries."""
     db_api.host_create(_get_fake_host_values(id=1))
     db_api.host_extra_capability_create(
         _get_fake_host_extra_capabilities(computehost_id=1))
     self.assertEqual(1, len(db_api.host_get_all_by_queries(['vgpu == 2'])))
     self.assertEqual(0, len(db_api.host_get_all_by_queries(['vgpu != 2'])))
     self.assertEqual(
         1,
         len(
             db_api.host_get_all_by_queries(
                 ['cpu_info like %Westmere%', 'vgpu == 2'])))
     self.assertEqual(
         0,
         len(
             db_api.host_get_all_by_queries(
                 ['cpu_info like %wrongcpu%', 'vgpu == 2'])))
     self.assertRaises(db_exceptions.ClimateDBNotFound,
                       db_api.host_get_all_by_queries, ['apples < 2048'])
Esempio n. 10
0
    def test_search_for_hosts_by_composed_queries(self):
        """Create one host and test composed queries."""

        db_api.host_create(_get_fake_host_values(mem=8192))
        self.assertEqual(1, len(
            db_api.host_get_all_by_queries(['memory_mb > 2048',
                                            'cpu_info like %Westmere%'])))
        self.assertEqual(0, len(
            db_api.host_get_all_by_queries(['memory_mb < 2048',
                                            'cpu_info like %Westmere%'])))
        self.assertRaises(db_exceptions.ClimateDBInvalidFilter,
                          db_api.host_get_all_by_queries, ['memory_mb <'])
        self.assertRaises(db_exceptions.ClimateDBNotFound,
                          db_api.host_get_all_by_queries, ['apples < 2048'])
        self.assertRaises(db_exceptions.ClimateDBInvalidFilterOperator,
                          db_api.host_get_all_by_queries,
                          ['memory_mb wrongop 2048'])
        self.assertEqual(1, len(
            db_api.host_get_all_by_queries(['memory_mb in 4096,8192'])))
        self.assertEqual(1, len(
            db_api.host_get_all_by_queries(['memory_mb != null'])))
Esempio n. 11
0
 def test_get_hosts_per_filter(self):
     db_api.host_create(_get_fake_host_values(id=1))
     db_api.host_create(_get_fake_host_values(id=2))
     filters = {"status": "free"}
     self.assertEqual(2, len(db_api.host_get_all_by_filters(filters)))
Esempio n. 12
0
 def test_list_hosts(self):
     db_api.host_create(_get_fake_host_values(id=1))
     db_api.host_create(_get_fake_host_values(id=2))
     self.assertEqual(2, len(db_api.host_list()))
Esempio n. 13
0
    def test_search_for_hosts_by_cpu_info(self):
        """Create one host and search within cpu_info."""

        db_api.host_create(_get_fake_host_values())
        self.assertEqual(1, len(db_api.host_get_all_by_queries(["cpu_info like %Westmere%"])))
Esempio n. 14
0
 def test_list_hosts(self):
     db_api.host_create(_get_fake_host_values(id=1))
     db_api.host_create(_get_fake_host_values(id=2))
     self.assertEqual(2, len(db_api.host_list()))
Esempio n. 15
0
 def test_delete_host(self):
     db_api.host_create(_get_fake_host_values(id=1))
     db_api.host_destroy(1)
     self.assertEqual(None, db_api.host_get(1))
     self.assertRaises(db_exceptions.ClimateDBNotFound,
                       db_api.host_destroy, 2)
Esempio n. 16
0
 def test_update_host(self):
     db_api.host_create(_get_fake_host_values(id=1))
     db_api.host_update(1, {'status': 'updated'})
     self.assertEqual('updated', db_api.host_get(1)['status'])
Esempio n. 17
0
 def test_create_duplicated_host(self):
     """Create a duplicated host and verify that an exception is raised."""
     db_api.host_create(_get_fake_host_values(id='1'))
     # Making sure we still raise a DuplicateDBEntry
     self.assertRaises(db_exceptions.ClimateDBDuplicateEntry,
                       db_api.host_create, _get_fake_host_values(id='1'))
Esempio n. 18
0
 def test_update_host(self):
     db_api.host_create(_get_fake_host_values(id=1))
     db_api.host_update(1, {"status": "updated"})
     self.assertEqual("updated", db_api.host_get(1)["status"])
Esempio n. 19
0
 def test_create_host(self):
     """Create a host and verify that all tables have been populated."""
     result = db_api.host_create(_get_fake_host_values(id='1'))
     self.assertEqual(result['id'], _get_fake_host_values(id='1')['id'])
Esempio n. 20
0
 def test_delete_host(self):
     db_api.host_create(_get_fake_host_values(id=1))
     db_api.host_destroy(1)
     self.assertEqual(None, db_api.host_get(1))
     self.assertRaises(db_exceptions.ClimateDBNotFound, db_api.host_destroy,
                       2)
Esempio n. 21
0
 def test_update_host(self):
     db_api.host_create(_get_fake_host_values(id=1))
     db_api.host_update(1, {'status': 'updated'})
     self.assertEqual('updated', db_api.host_get(1)['status'])
Esempio n. 22
0
 def test_get_hosts_per_filter(self):
     db_api.host_create(_get_fake_host_values(id=1))
     db_api.host_create(_get_fake_host_values(id=2))
     filters = {'status': 'free'}
     self.assertEqual(2, len(db_api.host_get_all_by_filters(filters)))
Esempio n. 23
0
 def test_delete_host(self):
     db_api.host_create(_get_fake_host_values(id=1))
     db_api.host_destroy(1)
     self.assertEqual(None, db_api.host_get(1))
     self.assertRaises(RuntimeError, db_api.host_destroy, 2)
Esempio n. 24
0
 def test_create_host(self):
     """Create a host and verify that all tables have been populated."""
     result = db_api.host_create(_get_fake_host_values(id='1'))
     self.assertEqual(result['id'], _get_fake_host_values(id='1')['id'])