Exemple #1
0
    def test_commit_multiple_objects(self):
        db_api.start_tx()

        try:
            created = db_api.create_listener(LISTENERS[0])
            fetched = db_api.get_listener(created.name)

            self.assertEqual(created, fetched)

            created_wb = db_api.create_member(MEMBERS[0])
            fetched_wb = db_api.get_member(created_wb.name)

            self.assertEqual(created_wb, fetched_wb)
            self.assertTrue(self.is_db_session_open())

            db_api.commit_tx()
        finally:
            db_api.end_tx()

        self.assertFalse(self.is_db_session_open())

        fetched = db_api.get_listener(created.name)

        self.assertEqual(created, fetched)

        fetched_wb = db_api.get_member(created_wb.name)

        self.assertEqual(created_wb, fetched_wb)
        self.assertFalse(self.is_db_session_open())
    def test_commit_multiple_objects(self):
        db_api.start_tx()

        try:
            created = db_api.create_listener(LISTENERS[0])
            fetched = db_api.get_listener(created.name)

            self.assertEqual(created, fetched)

            created_wb = db_api.create_member(MEMBERS[0])
            fetched_wb = db_api.get_member(created_wb.name)

            self.assertEqual(created_wb, fetched_wb)
            self.assertTrue(self.is_db_session_open())

            db_api.commit_tx()
        finally:
            db_api.end_tx()

        self.assertFalse(self.is_db_session_open())

        fetched = db_api.get_listener(created.name)

        self.assertEqual(created, fetched)

        fetched_wb = db_api.get_member(created_wb.name)

        self.assertEqual(created_wb, fetched_wb)
        self.assertFalse(self.is_db_session_open())
Exemple #3
0
    def test_update_member(self, replace_file):
        listener = db_api.create_listener({
            'name': 'test_listener',
            'description': 'my test settings',
            'protocol': 'http',
            'protocol_port': 80,
            'algorithm': 'roundrobin'
        })

        # Create a listener first.
        self.haproxy.create_listener(listener)

        listener = db_api.get_listener('test_listener')

        member = db_api.create_member({
            'listener_id': listener.id,
            'name': 'member1',
            'address': '10.0.0.1',
            'protocol_port': 80,
        })

        member = self.haproxy.create_member(member)

        self.assertEqual(80, member.protocol_port)

        member = db_api.update_member(member.name, {'protocol_port': 8080})

        self.haproxy.update_member(member)

        config_data = replace_file.call_args[0][1]

        self.assertIn(
            '\tserver %s %s:%s' % (member.name, member.address, 8080),
            config_data
        )
Exemple #4
0
    def test_update_listener(self, replace_file):
        listener = db_api.create_listener({
            'name': 'test_listener',
            'description': 'my test settings',
            'protocol': 'http',
            'protocol_port': 80,
            'algorithm': 'roundrobin',
            'address': ''
        })

        self.haproxy.create_listener(listener)

        listener = db_api.get_listener('test_listener')

        db_api.update_listener(listener.name, {'protocol_port': 8080})

        self.haproxy.update_listener(listener)

        config_data = replace_file.call_args[0][1]

        self.assertIn(
            'frontend %s' % listener.name,
            config_data
        )

        self.assertIn(
            'bind :%s' % 8080,
            config_data
        )
Exemple #5
0
    def test_rollback_multiple_objects(self):
        db_api.start_tx()

        try:
            created = db_api.create_listener(LISTENERS[0])
            fetched = db_api.get_listener(created['name'])

            self.assertEqual(created, fetched)

            created_wb = db_api.create_member(MEMBERS[0])
            fetched_wb = db_api.get_member(created_wb.name)

            self.assertEqual(created_wb, fetched_wb)
            self.assertTrue(self.is_db_session_open())

            db_api.rollback_tx()
        finally:
            db_api.end_tx()

        self.assertFalse(self.is_db_session_open())
        self.assertRaises(
            exc.NotFoundException,
            db_api.get_listener,
            created.name
        )
        self.assertRaises(
            exc.NotFoundException,
            db_api.get_member,
            created_wb.name
        )

        self.assertFalse(self.is_db_session_open())
Exemple #6
0
    def test_delete_listener(self, replace_file):
        # Create a listener first.
        listener = db_api.create_listener({
            'name': 'test_listener',
            'description': 'my test settings',
            'protocol': 'http',
            'protocol_port': 80,
            'algorithm': 'roundrobin'
        })

        self.haproxy.create_listener(listener)

        listener = db_api.get_listener('test_listener')

        config_data = replace_file.call_args[0][1]

        self.assertIn('frontend %s' % listener.name, config_data)

        db_api.delete_listener(listener.name)

        self.haproxy.delete_listener(listener.name)

        config_data = replace_file.call_args[0][1]

        self.assertNotIn('frontend %s' % listener.name, config_data)
        self.assertRaises(exc.NotFoundException, db_api.get_listener,
                          listener.name)
Exemple #7
0
    def test_create_member(self, replace_file):
        listener = db_api.create_listener({
            'name': 'test_listener',
            'description': 'my test settings',
            'protocol': 'http',
            'protocol_port': 80,
            'algorithm': 'roundrobin'
        })

        # Create a listener first.
        self.haproxy.create_listener(listener)

        listener = db_api.get_listener('test_listener')

        member = db_api.create_member({
            'listener_id': listener.id,
            'name': 'member1',
            'address': '10.0.0.1',
            'protocol_port': 80,
        })

        self.haproxy.create_member(member)

        member = db_api.get_member('member1')

        self.assertEqual('10.0.0.1', member.address)

        self.assertEqual(2, replace_file.call_count)

        config_data = replace_file.call_args[0][1]
        self.assertIn(
            '\tserver %s %s:%s' %
            (member.name, member.address, member.protocol_port), config_data)
    def test_delete_listener(self):
        created = db_api.create_listener(LISTENERS[0])

        fetched = db_api.get_listener(created.name)

        self.assertEqual(created, fetched)

        db_api.delete_listener(created.name)

        self.assertRaises(exc.NotFoundException, db_api.get_listener, created.name)
Exemple #9
0
    def test_create_and_get_and_load_listener(self):
        created = db_api.create_listener(LISTENERS[0])

        fetched = db_api.get_listener(created.name)

        self.assertEqual(created, fetched)

        fetched = db_api.load_listener(created.name)

        self.assertEqual(created, fetched)

        self.assertIsNone(db_api.load_listener("not-existing-id"))
    def test_create_and_get_and_load_listener(self):
        created = db_api.create_listener(LISTENERS[0])

        fetched = db_api.get_listener(created.name)

        self.assertEqual(created, fetched)

        fetched = db_api.load_listener(created.name)

        self.assertEqual(created, fetched)

        self.assertIsNone(db_api.load_listener("not-existing-id"))
    def test_update_listener(self):
        created = db_api.create_listener(LISTENERS[0])

        self.assertIsNone(created.updated_at)

        updated = db_api.update_listener(created.name, {"description": "my new desc"})

        self.assertEqual("my new desc", updated.description)

        fetched = db_api.get_listener(created.name)

        self.assertEqual(updated, fetched)
        self.assertIsNotNone(fetched.updated_at)
Exemple #12
0
    def test_delete_listener(self):
        created = db_api.create_listener(LISTENERS[0])

        fetched = db_api.get_listener(created.name)

        self.assertEqual(created, fetched)

        db_api.delete_listener(created.name)

        self.assertRaises(
            exc.NotFoundException,
            db_api.get_listener,
            created.name
        )
Exemple #13
0
    def test_delete_member(self, replace_file):
        listener = db_api.create_listener({
            'name': 'test_listener',
            'description': 'my test settings',
            'protocol': 'http',
            'protocol_port': 80,
            'algorithm': 'roundrobin'
        })

        # Create a listener first.
        self.haproxy.create_listener(listener)

        listener = db_api.get_listener('test_listener')

        member = db_api.create_member({
            'listener_id': listener.id,
            'name': 'member1',
            'address': '10.0.0.1',
            'protocol_port': 80,
        })

        self.haproxy.create_member(member)

        member = db_api.get_member('member1')

        config_data = replace_file.call_args[0][1]

        self.assertIn(
            '\tserver %s %s:%s' %
            (member.name, member.address, member.protocol_port),
            config_data
        )

        db_api.delete_member(member.name)

        self.haproxy.delete_member(member)

        config_data = replace_file.call_args[0][1]

        self.assertNotIn(
            '\tserver %s %s:%s' %
            (member.name, member.address, member.protocol_port),
            config_data
        )
        self.assertRaises(
            exc.NotFoundException,
            db_api.get_member,
            member.name
        )
Exemple #14
0
    def test_update_listener(self):
        created = db_api.create_listener(LISTENERS[0])

        self.assertIsNone(created.updated_at)

        updated = db_api.update_listener(
            created.name,
            {'description': 'my new desc'}
        )

        self.assertEqual('my new desc', updated.description)

        fetched = db_api.get_listener(created.name)

        self.assertEqual(updated, fetched)
        self.assertIsNotNone(fetched.updated_at)
Exemple #15
0
    def test_create_listener(self, replace_file):
        listener = db_api.create_listener({
            'name': 'test_listener',
            'description': 'my test settings',
            'protocol': 'http',
            'protocol_port': 80,
            'algorithm': 'roundrobin'
        })

        self.haproxy.create_listener(listener)

        listener = db_api.get_listener('test_listener')

        self.assertEqual('roundrobin', listener.algorithm)

        config_data = replace_file.call_args[0][1]

        self.assertIn('frontend %s' % listener.name, config_data)
    def test_create_or_update_listener(self):
        name = "not-existing-id"

        self.assertIsNone(db_api.load_listener(name))

        created = db_api.create_or_update_listener(name, LISTENERS[0])

        self.assertIsNotNone(created)
        self.assertIsNotNone(created.name)

        updated = db_api.create_or_update_listener(created.name, {"description": "my new desc"})

        self.assertEqual("my new desc", updated.description)
        self.assertEqual("my new desc", db_api.load_listener(updated.name).description)

        fetched = db_api.get_listener(created.name)

        self.assertEqual(updated, fetched)
Exemple #17
0
    def test_create_or_update_listener(self):
        name = 'not-existing-id'

        self.assertIsNone(db_api.load_listener(name))

        created = db_api.create_or_update_listener(name, LISTENERS[0])

        self.assertIsNotNone(created)
        self.assertIsNotNone(created.name)

        updated = db_api.create_or_update_listener(
            created.name,
            {'description': 'my new desc'}
        )

        self.assertEqual('my new desc', updated.description)
        self.assertEqual(
            'my new desc',
            db_api.load_listener(updated.name).description
        )

        fetched = db_api.get_listener(created.name)

        self.assertEqual(updated, fetched)
    def test_rollback_multiple_objects(self):
        db_api.start_tx()

        try:
            created = db_api.create_listener(LISTENERS[0])
            fetched = db_api.get_listener(created["name"])

            self.assertEqual(created, fetched)

            created_wb = db_api.create_member(MEMBERS[0])
            fetched_wb = db_api.get_member(created_wb.name)

            self.assertEqual(created_wb, fetched_wb)
            self.assertTrue(self.is_db_session_open())

            db_api.rollback_tx()
        finally:
            db_api.end_tx()

        self.assertFalse(self.is_db_session_open())
        self.assertRaises(exc.NotFoundException, db_api.get_listener, created.name)
        self.assertRaises(exc.NotFoundException, db_api.get_member, created_wb.name)

        self.assertFalse(self.is_db_session_open())
Exemple #19
0
    def test_delete_listener(self, replace_file):
        # Create a listener first.
        listener = db_api.create_listener({
            'name': 'test_listener',
            'description': 'my test settings',
            'protocol': 'http',
            'protocol_port': 80,
            'algorithm': 'roundrobin'
        })

        self.haproxy.create_listener(listener)

        listener = db_api.get_listener('test_listener')

        config_data = replace_file.call_args[0][1]

        self.assertIn(
            'frontend %s' % listener.name,
            config_data
        )

        db_api.delete_listener(listener.name)

        self.haproxy.delete_listener(listener.name)

        config_data = replace_file.call_args[0][1]

        self.assertNotIn(
            'frontend %s' % listener.name,
            config_data
        )
        self.assertRaises(
            exc.NotFoundException,
            db_api.get_listener,
            listener.name
        )