def test_get_members(self):
        created0 = db_api.create_member(MEMBERS[0])
        created1 = db_api.create_member(MEMBERS[1])

        fetched = db_api.get_members()

        self.assertEqual(2, len(fetched))
        self.assertEqual(created0, fetched[0])
        self.assertEqual(created1, fetched[1])
Beispiel #2
0
    def test_get_members(self):
        created0 = db_api.create_member(MEMBERS[0])
        created1 = db_api.create_member(MEMBERS[1])

        fetched = db_api.get_members()

        self.assertEqual(2, len(fetched))
        self.assertEqual(created0, fetched[0])
        self.assertEqual(created1, fetched[1])
    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())
Beispiel #4
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
        )
Beispiel #5
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())
Beispiel #6
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())
    def test_rollback_transaction(self):
        try:
            with db_api.transaction():
                created = db_api.create_member(MEMBERS[0])
                fetched = db_api.get_member(created.name)

                self.assertEqual(created, fetched)
                self.assertTrue(self.is_db_session_open())

                db_api.create_member(MEMBERS[0])

        except exc.DBDuplicateEntryException:
            pass

        self.assertFalse(self.is_db_session_open())
        self.assertRaises(exc.NotFoundException, db_api.get_member, created.name)
Beispiel #8
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_member(self):
        created = db_api.create_member(MEMBERS[0])

        fetched = db_api.get_member(created.name)

        self.assertEqual(created, fetched)

        db_api.delete_member(created.name)

        self.assertRaises(exc.NotFoundException, db_api.get_member, created.name)
Beispiel #10
0
    def test_rollback_transaction(self):
        try:
            with db_api.transaction():
                created = db_api.create_member(MEMBERS[0])
                fetched = db_api.get_member(created.name)

                self.assertEqual(created, fetched)
                self.assertTrue(self.is_db_session_open())

                db_api.create_member(MEMBERS[0])

        except exc.DBDuplicateEntryException:
            pass

        self.assertFalse(self.is_db_session_open())
        self.assertRaises(
            exc.NotFoundException,
            db_api.get_member,
            created.name
        )
    def test_create_and_get_and_load_member(self):
        created = db_api.create_member(MEMBERS[0])

        fetched = db_api.get_member(created["name"])

        self.assertEqual(created, fetched)

        fetched = db_api.load_member(created.name)

        self.assertEqual(created, fetched)

        self.assertIsNone(db_api.load_member("not-existing-wb"))
Beispiel #12
0
    def test_create_and_get_and_load_member(self):
        created = db_api.create_member(MEMBERS[0])

        fetched = db_api.get_member(created['name'])

        self.assertEqual(created, fetched)

        fetched = db_api.load_member(created.name)

        self.assertEqual(created, fetched)

        self.assertIsNone(db_api.load_member("not-existing-wb"))
    def test_update_member(self):
        created = db_api.create_member(MEMBERS[0])

        self.assertIsNone(created.updated_at)

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

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

        fetched = db_api.get_member(created["name"])

        self.assertEqual(updated, fetched)
        self.assertIsNotNone(fetched.updated_at)
Beispiel #14
0
    def test_commit_transaction(self):
        with db_api.transaction():
            created = db_api.create_member(MEMBERS[0])
            fetched = db_api.get_member(created.name)

            self.assertEqual(created, fetched)
            self.assertTrue(self.is_db_session_open())

        self.assertFalse(self.is_db_session_open())

        fetched = db_api.get_member(created.name)

        self.assertEqual(created, fetched)
        self.assertFalse(self.is_db_session_open())
Beispiel #15
0
    def test_delete_member(self):
        created = db_api.create_member(MEMBERS[0])

        fetched = db_api.get_member(created.name)

        self.assertEqual(created, fetched)

        db_api.delete_member(created.name)

        self.assertRaises(
            exc.NotFoundException,
            db_api.get_member,
            created.name
        )
    def test_commit_transaction(self):
        with db_api.transaction():
            created = db_api.create_member(MEMBERS[0])
            fetched = db_api.get_member(created.name)

            self.assertEqual(created, fetched)
            self.assertTrue(self.is_db_session_open())

        self.assertFalse(self.is_db_session_open())

        fetched = db_api.get_member(created.name)

        self.assertEqual(created, fetched)
        self.assertFalse(self.is_db_session_open())
Beispiel #17
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
        )
Beispiel #18
0
    def test_update_member(self):
        created = db_api.create_member(MEMBERS[0])

        self.assertIsNone(created.updated_at)

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

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

        fetched = db_api.get_member(created['name'])

        self.assertEqual(updated, fetched)
        self.assertIsNotNone(fetched.updated_at)
    def test_rollback(self):
        db_api.start_tx()

        try:
            created = db_api.create_member(MEMBERS[0])
            fetched = db_api.get_member(created.name)

            self.assertEqual(created, fetched)
            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_member, created["id"])
        self.assertFalse(self.is_db_session_open())
Beispiel #20
0
    def test_commit(self):
        db_api.start_tx()

        try:
            created = db_api.create_member(MEMBERS[0])
            fetched = db_api.get_member(created.name)

            self.assertEqual(created, fetched)
            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_member(created.name)

        self.assertEqual(created, fetched)
        self.assertFalse(self.is_db_session_open())
    def test_commit(self):
        db_api.start_tx()

        try:
            created = db_api.create_member(MEMBERS[0])
            fetched = db_api.get_member(created.name)

            self.assertEqual(created, fetched)
            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_member(created.name)

        self.assertEqual(created, fetched)
        self.assertFalse(self.is_db_session_open())
Beispiel #22
0
    def test_rollback(self):
        db_api.start_tx()

        try:
            created = db_api.create_member(MEMBERS[0])
            fetched = db_api.get_member(created.name)

            self.assertEqual(created, fetched)
            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_member,
            created['id']
        )
        self.assertFalse(self.is_db_session_open())
    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())
Beispiel #24
0
    def test_member_repr(self):
        s = db_api.create_member(MEMBERS[0]).__repr__()

        self.assertIn('Member ', s)
        self.assertIn("'name': 'my_member1'", s)
    def test_member_repr(self):
        s = db_api.create_member(MEMBERS[0]).__repr__()

        self.assertIn("Member ", s)
        self.assertIn("'name': 'my_member1'", s)