Exemple #1
0
    def testCreateMysqlUpdatesServerRolesTableWhenNothingToUpdate(self):
        """Test create_mysql_updates with servers table."""
        api_output = {
            'servers': [],
            'server_attributes': [],
            'server_roles': [sds.ServerRole('foo', 'afe')]
        }
        db_output = {
            'servers': [],
            'server_attributes': [],
            'server_roles': [sds.ServerRole('foo', 'afe')]
        }
        table = 'server_roles'
        server_id_map = {'foo': 1}

        result = sds.create_mysql_updates(api_output, db_output, table,
                                          server_id_map, False)
        expect_returns = []
        self.assertEqual(expect_returns, result)
Exemple #2
0
    def testCreateMysqlUpdatesServersTableWhenDbIsInconsistent(self):
        """Test create_mysql_updates with servers table."""
        api_output = {
            'servers': [sds.Server('foo', None, 'backup', '')],
            'server_attributes': [],
            'server_roles': []
        }
        db_output = {
            'servers': [sds.Server('foo', None, 'primary', '')],
            'server_attributes': [],
            'server_roles': []
        }
        table = 'servers'
        server_id_map = {'foo': 1}

        result = sds.create_mysql_updates(api_output, db_output, table,
                                          server_id_map, False)
        delete_cmd = "DELETE FROM servers WHERE hostname='foo'"
        insert_cmd = ("INSERT INTO servers (hostname, cname, status, note) "
                      "VALUES('foo', NULL, 'backup', '')")
        self.assertEqual([delete_cmd, insert_cmd], result)
Exemple #3
0
    def testCreateMysqlUpdatesServerRolesTableWhenDbIsInconsistent(self):
        """Test create_mysql_updates with servers table."""
        api_output = {
            'servers': [],
            'server_attributes': [],
            'server_roles': [sds.ServerRole('foo', 'afe')]
        }
        db_output = {
            'servers': [],
            'server_attributes': [],
            'server_roles':
            [sds.ServerRole('foo', 'afe'),
             sds.ServerRole('bar', 'scheduler')]
        }
        table = 'server_roles'
        server_id_map = {'foo': 1, 'bar': 2}

        result = sds.create_mysql_updates(api_output, db_output, table,
                                          server_id_map, False)
        delete_cmd = ("DELETE FROM server_roles WHERE server_id=2 "
                      "and role='scheduler'")
        self.assertEqual([delete_cmd], result)
Exemple #4
0
    def testCreateMysqlUpdatesServersAttrsTableWhenDbIsInconsistent(self):
        """Test create_mysql_updates with servers table."""
        api_output = {
            'server_attributes': [
                sds.ServerAttribute('foo', 'ip', '1'),
                sds.ServerAttribute('bar', 'ip', '2')
            ],
            'servers': [],
            'server_roles': []
        }
        db_output = {
            'server_attributes': [sds.ServerAttribute('foo', 'ip', '1')],
            'servers': [],
            'server_roles': []
        }
        table = 'server_attributes'
        server_id_map = {'foo': 1, 'bar': 2}

        result = sds.create_mysql_updates(api_output, db_output, table,
                                          server_id_map, False)
        insert_cmd = (
            "INSERT INTO server_attributes (server_id, attribute, value)"
            " VALUES(2, 'ip', '2')")
        self.assertEqual([insert_cmd], result)