<reponame>bopopescu/nova-token<filename>nova/tests/unit/objects/test_agent.py<gh_stars>0
begin_unit
comment|'#    Copyright 2014 Red Hat, Inc.'
nl|'\n'
comment|'#'
nl|'\n'
comment|'#    Licensed under the Apache License, Version 2.0 (the "License"); you may'
nl|'\n'
comment|'#    not use this file except in compliance with the License. You may obtain'
nl|'\n'
comment|'#    a copy of the License at'
nl|'\n'
comment|'#'
nl|'\n'
comment|'#         http://www.apache.org/licenses/LICENSE-2.0'
nl|'\n'
comment|'#'
nl|'\n'
comment|'#    Unless required by applicable law or agreed to in writing, software'
nl|'\n'
comment|'#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT'
nl|'\n'
comment|'#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the'
nl|'\n'
comment|'#    License for the specific language governing permissions and limitations'
nl|'\n'
comment|'#    under the License.'
nl|'\n'
nl|'\n'
name|'import'
name|'mock'
newline|'\n'
nl|'\n'
name|'from'
name|'nova'
name|'import'
name|'exception'
newline|'\n'
name|'from'
name|'nova'
op|'.'
name|'objects'
name|'import'
name|'agent'
name|'as'
name|'agent_obj'
newline|'\n'
name|'from'
name|'nova'
op|'.'
name|'tests'
op|'.'
name|'unit'
op|'.'
name|'objects'
name|'import'
name|'test_objects'
newline|'\n'
nl|'\n'
nl|'\n'
DECL|variable|fake_agent
name|'fake_agent'
op|'='
op|'{'
nl|'\n'
string|"'id'"
op|':'
number|'1'
op|','
nl|'\n'
string|"'hypervisor'"
op|':'
string|"'novavm'"
op|','
nl|'\n'
string|"'os'"
op|':'
string|"'linux'"
op|','
nl|'\n'
string|"'architecture'"
op|':'
string|"'DISC'"
op|','
nl|'\n'
string|"'version'"
op|':'
string|"'1.0'"
op|','
nl|'\n'
string|"'url'"
op|':'
string|"'http://openstack.org/novavm/agents/novavm_agent_v1.0.rpm'"
op|','
nl|'\n'
string|"'md5hash'"
op|':'
string|"'8cb151f3adc23a92db8ddbe084796823'"
op|','
nl|'\n'
string|"'created_at'"
op|':'
name|'None'
op|','
nl|'\n'
string|"'updated_at'"
op|':'
name|'None'
op|','
nl|'\n'
string|"'deleted_at'"
op|':'
name|'None'
op|','
nl|'\n'
string|"'deleted'"
op|':'
name|'False'
op|','
nl|'\n'
op|'}'
newline|'\n'
nl|'\n'
nl|'\n'
DECL|class|_TestAgent
name|'class'
name|'_TestAgent'
op|'('
name|'object'
op|')'
op|':'
newline|'\n'
indent|'    '
op|'@'
name|'staticmethod'
newline|'\n'
DECL|member|_compare
name|'def'
name|'_compare'
op|'('
name|'test'
op|','
name|'db'
op|','
name|'obj'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'for'
name|'field'
op|','
name|'value'
name|'in'
name|'db'
op|'.'
name|'items'
op|'('
op|')'
op|':'
newline|'\n'
indent|'            '
name|'test'
op|'.'
name|'assertEqual'
op|'('
name|'db'
op|'['
name|'field'
op|']'
op|','
name|'getattr'
op|'('
name|'obj'
op|','
name|'field'
op|')'
op|')'
newline|'\n'
nl|'\n'
dedent|''
dedent|''
op|'@'
name|'mock'
op|'.'
name|'patch'
op|'('
string|"'nova.db.agent_build_get_by_triple'"
op|')'
newline|'\n'
DECL|member|test_get_by_triple
name|'def'
name|'test_get_by_triple'
op|'('
name|'self'
op|','
name|'mock_get'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'mock_get'
op|'.'
name|'return_value'
op|'='
name|'fake_agent'
newline|'\n'
name|'agent'
op|'='
name|'agent_obj'
op|'.'
name|'Agent'
op|'.'
name|'get_by_triple'
op|'('
name|'self'
op|'.'
name|'context'
op|','
nl|'\n'
string|"'novavm'"
op|','
string|"'linux'"
op|','
string|"'DISC'"
op|')'
newline|'\n'
name|'self'
op|'.'
name|'_compare'
op|'('
name|'self'
op|','
name|'fake_agent'
op|','
name|'agent'
op|')'
newline|'\n'
nl|'\n'
dedent|''
op|'@'
name|'mock'
op|'.'
name|'patch'
op|'('
string|"'nova.db.agent_build_get_by_triple'"
op|')'
newline|'\n'
DECL|member|test_get_by_triple_none
name|'def'
name|'test_get_by_triple_none'
op|'('
name|'self'
op|','
name|'mock_get'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'mock_get'
op|'.'
name|'return_value'
op|'='
name|'None'
newline|'\n'
name|'agent'
op|'='
name|'agent_obj'
op|'.'
name|'Agent'
op|'.'
name|'get_by_triple'
op|'('
name|'self'
op|'.'
name|'context'
op|','
nl|'\n'
string|"'novavm'"
op|','
string|"'linux'"
op|','
string|"'DISC'"
op|')'
newline|'\n'
name|'self'
op|'.'
name|'assertIsNone'
op|'('
name|'agent'
op|')'
newline|'\n'
nl|'\n'
dedent|''
op|'@'
name|'mock'
op|'.'
name|'patch'
op|'('
string|"'nova.db.agent_build_create'"
op|')'
newline|'\n'
DECL|member|test_create
name|'def'
name|'test_create'
op|'('
name|'self'
op|','
name|'mock_create'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'mock_create'
op|'.'
name|'return_value'
op|'='
name|'fake_agent'
newline|'\n'
name|'agent'
op|'='
name|'agent_obj'
op|'.'
name|'Agent'
op|'('
name|'context'
op|'='
name|'self'
op|'.'
name|'context'
op|')'
newline|'\n'
name|'agent'
op|'.'
name|'hypervisor'
op|'='
string|"'novavm'"
newline|'\n'
name|'agent'
op|'.'
name|'create'
op|'('
op|')'
newline|'\n'
name|'mock_create'
op|'.'
name|'assert_called_once_with'
op|'('
name|'self'
op|'.'
name|'context'
op|','
nl|'\n'
op|'{'
string|"'hypervisor'"
op|':'
string|"'novavm'"
op|'}'
op|')'
newline|'\n'
name|'self'
op|'.'
name|'_compare'
op|'('
name|'self'
op|','
name|'fake_agent'
op|','
name|'agent'
op|')'
newline|'\n'
nl|'\n'
dedent|''
op|'@'
name|'mock'
op|'.'
name|'patch'
op|'('
string|"'nova.db.agent_build_create'"
op|')'
newline|'\n'
DECL|member|test_create_with_id
name|'def'
name|'test_create_with_id'
op|'('
name|'self'
op|','
name|'mock_create'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'agent'
op|'='
name|'agent_obj'
op|'.'
name|'Agent'
op|'('
name|'context'
op|'='
name|'self'
op|'.'
name|'context'
op|','
name|'id'
op|'='
number|'123'
op|')'
newline|'\n'
name|'self'
op|'.'
name|'assertRaises'
op|'('
name|'exception'
op|'.'
name|'ObjectActionError'
op|','
name|'agent'
op|'.'
name|'create'
op|')'
newline|'\n'
name|'self'
op|'.'
name|'assertFalse'
op|'('
name|'mock_create'
op|'.'
name|'called'
op|')'
newline|'\n'
nl|'\n'
dedent|''
op|'@'
name|'mock'
op|'.'
name|'patch'
op|'('
string|"'nova.db.agent_build_destroy'"
op|')'
newline|'\n'
DECL|member|test_destroy
name|'def'
name|'test_destroy'
op|'('
name|'self'
op|','
name|'mock_destroy'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'agent'
op|'='
name|'agent_obj'
op|'.'
name|'Agent'
op|'('
name|'context'
op|'='
name|'self'
op|'.'
name|'context'
op|','
name|'id'
op|'='
number|'123'
op|')'
newline|'\n'
name|'agent'
op|'.'
name|'destroy'
op|'('
op|')'
newline|'\n'
name|'mock_destroy'
op|'.'
name|'assert_called_once_with'
op|'('
name|'self'
op|'.'
name|'context'
op|','
number|'123'
op|')'
newline|'\n'
nl|'\n'
dedent|''
op|'@'
name|'mock'
op|'.'
name|'patch'
op|'('
string|"'nova.db.agent_build_update'"
op|')'
newline|'\n'
DECL|member|test_save
name|'def'
name|'test_save'
op|'('
name|'self'
op|','
name|'mock_update'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'mock_update'
op|'.'
name|'return_value'
op|'='
name|'fake_agent'
newline|'\n'
name|'agent'
op|'='
name|'agent_obj'
op|'.'
name|'Agent'
op|'('
name|'context'
op|'='
name|'self'
op|'.'
name|'context'
op|','
name|'id'
op|'='
number|'123'
op|')'
newline|'\n'
name|'agent'
op|'.'
name|'obj_reset_changes'
op|'('
op|')'
newline|'\n'
name|'agent'
op|'.'
name|'hypervisor'
op|'='
string|"'novavm'"
newline|'\n'
name|'agent'
op|'.'
name|'save'
op|'('
op|')'
newline|'\n'
name|'mock_update'
op|'.'
name|'assert_called_once_with'
op|'('
name|'self'
op|'.'
name|'context'
op|','
number|'123'
op|','
nl|'\n'
op|'{'
string|"'hypervisor'"
op|':'
string|"'novavm'"
op|'}'
op|')'
newline|'\n'
nl|'\n'
dedent|''
op|'@'
name|'mock'
op|'.'
name|'patch'
op|'('
string|"'nova.db.agent_build_get_all'"
op|')'
newline|'\n'
DECL|member|test_get_all
name|'def'
name|'test_get_all'
op|'('
name|'self'
op|','
name|'mock_get_all'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'mock_get_all'
op|'.'
name|'return_value'
op|'='
op|'['
name|'fake_agent'
op|']'
newline|'\n'
name|'agents'
op|'='
name|'agent_obj'
op|'.'
name|'AgentList'
op|'.'
name|'get_all'
op|'('
name|'self'
op|'.'
name|'context'
op|','
name|'hypervisor'
op|'='
string|"'novavm'"
op|')'
newline|'\n'
name|'self'
op|'.'
name|'assertEqual'
op|'('
number|'1'
op|','
name|'len'
op|'('
name|'agents'
op|')'
op|')'
newline|'\n'
name|'self'
op|'.'
name|'_compare'
op|'('
name|'self'
op|','
name|'fake_agent'
op|','
name|'agents'
op|'['
number|'0'
op|']'
op|')'
newline|'\n'
name|'mock_get_all'
op|'.'
name|'assert_called_once_with'
op|'('
name|'self'
op|'.'
name|'context'
op|','
name|'hypervisor'
op|'='
string|"'novavm'"
op|')'
newline|'\n'
nl|'\n'
nl|'\n'
DECL|class|TestAgent
dedent|''
dedent|''
name|'class'
name|'TestAgent'
op|'('
name|'test_objects'
op|'.'
name|'_LocalTest'
op|','
name|'_TestAgent'
op|')'
op|':'
newline|'\n'
indent|'    '
name|'pass'
newline|'\n'
nl|'\n'
nl|'\n'
DECL|class|TestAgentRemote
dedent|''
name|'class'
name|'TestAgentRemote'
op|'('
name|'test_objects'
op|'.'
name|'_RemoteTest'
op|','
name|'_TestAgent'
op|')'
op|':'
newline|'\n'
indent|'    '
name|'pass'
newline|'\n'
dedent|''
endmarker|''
end_unit

begin_unit
comment|'#    Copyright 2014 Red Hat, Inc.'
nl|'\n'
comment|'#'
nl|'\n'
comment|'#    Licensed under the Apache License, Version 2.0 (the "License"); you may'
nl|'\n'
comment|'#    not use this file except in compliance with the License. You may obtain'
nl|'\n'
comment|'#    a copy of the License at'
nl|'\n'
comment|'#'
nl|'\n'
comment|'#         http://www.apache.org/licenses/LICENSE-2.0'
nl|'\n'
comment|'#'
nl|'\n'
comment|'#    Unless required by applicable law or agreed to in writing, software'
nl|'\n'
comment|'#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT'
nl|'\n'
comment|'#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the'
nl|'\n'
comment|'#    License for the specific language governing permissions and limitations'
nl|'\n'
comment|'#    under the License.'
nl|'\n'
nl|'\n'
name|'import'
name|'mock'
newline|'\n'
nl|'\n'
name|'from'
name|'nova'
name|'import'
name|'exception'
newline|'\n'
name|'from'
name|'nova'
op|'.'
name|'objects'
name|'import'
name|'agent'
name|'as'
name|'agent_obj'
newline|'\n'
name|'from'
name|'nova'
op|'.'
name|'tests'
op|'.'
name|'unit'
op|'.'
name|'objects'
name|'import'
name|'test_objects'
newline|'\n'
nl|'\n'
nl|'\n'
DECL|variable|fake_agent
name|'fake_agent'
op|'='
op|'{'
nl|'\n'
string|"'id'"
op|':'
number|'1'
op|','
nl|'\n'
string|"'hypervisor'"
op|':'
string|"'novavm'"
op|','
nl|'\n'
string|"'os'"
op|':'
string|"'linux'"
op|','
nl|'\n'
string|"'architecture'"
op|':'
string|"'DISC'"
op|','
nl|'\n'
string|"'version'"
op|':'
string|"'1.0'"
op|','
nl|'\n'
string|"'url'"
op|':'
string|"'http://openstack.org/novavm/agents/novavm_agent_v1.0.rpm'"
op|','
nl|'\n'
string|"'md5hash'"
op|':'
string|"'8cb151f3adc23a92db8ddbe084796823'"
op|','
nl|'\n'
string|"'created_at'"
op|':'
name|'None'
op|','
nl|'\n'
string|"'updated_at'"
op|':'
name|'None'
op|','
nl|'\n'
string|"'deleted_at'"
op|':'
name|'None'
op|','
nl|'\n'
string|"'deleted'"
op|':'
name|'False'
op|','
nl|'\n'
op|'}'
newline|'\n'
nl|'\n'
nl|'\n'
DECL|class|_TestAgent
name|'class'
name|'_TestAgent'
op|'('
name|'object'
op|')'
op|':'
newline|'\n'
indent|'    '
op|'@'
name|'staticmethod'
newline|'\n'
DECL|member|_compare
name|'def'
name|'_compare'
op|'('
name|'test'
op|','
name|'db'
op|','
name|'obj'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'for'
name|'field'
op|','
name|'value'
name|'in'
name|'db'
op|'.'
name|'items'
op|'('
op|')'
op|':'
newline|'\n'
indent|'            '
name|'test'
op|'.'
name|'assertEqual'
op|'('
name|'db'
op|'['
name|'field'
op|']'
op|','
name|'getattr'
op|'('
name|'obj'
op|','
name|'field'
op|')'
op|')'
newline|'\n'
nl|'\n'
dedent|''
dedent|''
op|'@'
name|'mock'
op|'.'
name|'patch'
op|'('
string|"'nova.db.agent_build_get_by_triple'"
op|')'
newline|'\n'
DECL|member|test_get_by_triple
name|'def'
name|'test_get_by_triple'
op|'('
name|'self'
op|','
name|'mock_get'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'mock_get'
op|'.'
name|'return_value'
op|'='
name|'fake_agent'
newline|'\n'
name|'agent'
op|'='
name|'agent_obj'
op|'.'
name|'Agent'
op|'.'
name|'get_by_triple'
op|'('
name|'self'
op|'.'
name|'context'
op|','
nl|'\n'
string|"'novavm'"
op|','
string|"'linux'"
op|','
string|"'DISC'"
op|')'
newline|'\n'
name|'self'
op|'.'
name|'_compare'
op|'('
name|'self'
op|','
name|'fake_agent'
op|','
name|'agent'
op|')'
newline|'\n'
nl|'\n'
dedent|''
op|'@'
name|'mock'
op|'.'
name|'patch'
op|'('
string|"'nova.db.agent_build_get_by_triple'"
op|')'
newline|'\n'
DECL|member|test_get_by_triple_none
name|'def'
name|'test_get_by_triple_none'
op|'('
name|'self'
op|','
name|'mock_get'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'mock_get'
op|'.'
name|'return_value'
op|'='
name|'None'
newline|'\n'
name|'agent'
op|'='
name|'agent_obj'
op|'.'
name|'Agent'
op|'.'
name|'get_by_triple'
op|'('
name|'self'
op|'.'
name|'context'
op|','
nl|'\n'
string|"'novavm'"
op|','
string|"'linux'"
op|','
string|"'DISC'"
op|')'
newline|'\n'
name|'self'
op|'.'
name|'assertIsNone'
op|'('
name|'agent'
op|')'
newline|'\n'
nl|'\n'
dedent|''
op|'@'
name|'mock'
op|'.'
name|'patch'
op|'('
string|"'nova.db.agent_build_create'"
op|')'
newline|'\n'
DECL|member|test_create
name|'def'
name|'test_create'
op|'('
name|'self'
op|','
name|'mock_create'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'mock_create'
op|'.'
name|'return_value'
op|'='
name|'fake_agent'
newline|'\n'
name|'agent'
op|'='
name|'agent_obj'
op|'.'
name|'Agent'
op|'('
name|'context'
op|'='
name|'self'
op|'.'
name|'context'
op|')'
newline|'\n'
name|'agent'
op|'.'
name|'hypervisor'
op|'='
string|"'novavm'"
newline|'\n'
name|'agent'
op|'.'
name|'create'
op|'('
op|')'
newline|'\n'
name|'mock_create'
op|'.'
name|'assert_called_once_with'
op|'('
name|'self'
op|'.'
name|'context'
op|','
nl|'\n'
op|'{'
string|"'hypervisor'"
op|':'
string|"'novavm'"
op|'}'
op|')'
newline|'\n'
name|'self'
op|'.'
name|'_compare'
op|'('
name|'self'
op|','
name|'fake_agent'
op|','
name|'agent'
op|')'
newline|'\n'
nl|'\n'
dedent|''
op|'@'
name|'mock'
op|'.'
name|'patch'
op|'('
string|"'nova.db.agent_build_create'"
op|')'
newline|'\n'
DECL|member|test_create_with_id
name|'def'
name|'test_create_with_id'
op|'('
name|'self'
op|','
name|'mock_create'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'agent'
op|'='
name|'agent_obj'
op|'.'
name|'Agent'
op|'('
name|'context'
op|'='
name|'self'
op|'.'
name|'context'
op|','
name|'id'
op|'='
number|'123'
op|')'
newline|'\n'
name|'self'
op|'.'
name|'assertRaises'
op|'('
name|'exception'
op|'.'
name|'ObjectActionError'
op|','
name|'agent'
op|'.'
name|'create'
op|')'
newline|'\n'
name|'self'
op|'.'
name|'assertFalse'
op|'('
name|'mock_create'
op|'.'
name|'called'
op|')'
newline|'\n'
nl|'\n'
dedent|''
op|'@'
name|'mock'
op|'.'
name|'patch'
op|'('
string|"'nova.db.agent_build_destroy'"
op|')'
newline|'\n'
DECL|member|test_destroy
name|'def'
name|'test_destroy'
op|'('
name|'self'
op|','
name|'mock_destroy'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'agent'
op|'='
name|'agent_obj'
op|'.'
name|'Agent'
op|'('
name|'context'
op|'='
name|'self'
op|'.'
name|'context'
op|','
name|'id'
op|'='
number|'123'
op|')'
newline|'\n'
name|'agent'
op|'.'
name|'destroy'
op|'('
op|')'
newline|'\n'
name|'mock_destroy'
op|'.'
name|'assert_called_once_with'
op|'('
name|'self'
op|'.'
name|'context'
op|','
number|'123'
op|')'
newline|'\n'
nl|'\n'
dedent|''
op|'@'
name|'mock'
op|'.'
name|'patch'
op|'('
string|"'nova.db.agent_build_update'"
op|')'
newline|'\n'
DECL|member|test_save
name|'def'
name|'test_save'
op|'('
name|'self'
op|','
name|'mock_update'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'mock_update'
op|'.'
name|'return_value'
op|'='
name|'fake_agent'
newline|'\n'
name|'agent'
op|'='
name|'agent_obj'
op|'.'
name|'Agent'
op|'('
name|'context'
op|'='
name|'self'
op|'.'
name|'context'
op|','
name|'id'
op|'='
number|'123'
op|')'
newline|'\n'
name|'agent'
op|'.'
name|'obj_reset_changes'
op|'('
op|')'
newline|'\n'
name|'agent'
op|'.'
name|'hypervisor'
op|'='
string|"'novavm'"
newline|'\n'
name|'agent'
op|'.'
name|'save'
op|'('
op|')'
newline|'\n'
name|'mock_update'
op|'.'
name|'assert_called_once_with'
op|'('
name|'self'
op|'.'
name|'context'
op|','
number|'123'
op|','
nl|'\n'
op|'{'
string|"'hypervisor'"
op|':'
string|"'novavm'"
op|'}'
op|')'
newline|'\n'
nl|'\n'
dedent|''
op|'@'
name|'mock'
op|'.'
name|'patch'
op|'('
string|"'nova.db.agent_build_get_all'"
op|')'
newline|'\n'
DECL|member|test_get_all
name|'def'
name|'test_get_all'
op|'('
name|'self'
op|','
name|'mock_get_all'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'mock_get_all'
op|'.'
name|'return_value'
op|'='
op|'['
name|'fake_agent'
op|']'
newline|'\n'
name|'agents'
op|'='
name|'agent_obj'
op|'.'
name|'AgentList'
op|'.'
name|'get_all'
op|'('
name|'self'
op|'.'
name|'context'
op|','
name|'hypervisor'
op|'='
string|"'novavm'"
op|')'
newline|'\n'
name|'self'
op|'.'
name|'assertEqual'
op|'('
number|'1'
op|','
name|'len'
op|'('
name|'agents'
op|')'
op|')'
newline|'\n'
name|'self'
op|'.'
name|'_compare'
op|'('
name|'self'
op|','
name|'fake_agent'
op|','
name|'agents'
op|'['
number|'0'
op|']'
op|')'
newline|'\n'
name|'mock_get_all'
op|'.'
name|'assert_called_once_with'
op|'('
name|'self'
op|'.'
name|'context'
op|','
name|'hypervisor'
op|'='
string|"'novavm'"
op|')'
newline|'\n'
nl|'\n'
nl|'\n'
DECL|class|TestAgent
dedent|''
dedent|''
name|'class'
name|'TestAgent'
op|'('
name|'test_objects'
op|'.'
name|'_LocalTest'
op|','
name|'_TestAgent'
op|')'
op|':'
newline|'\n'
indent|'    '
name|'pass'
newline|'\n'
nl|'\n'
nl|'\n'
DECL|class|TestAgentRemote
dedent|''
name|'class'
name|'TestAgentRemote'
op|'('
name|'test_objects'
op|'.'
name|'_RemoteTest'
op|','
name|'_TestAgent'
op|')'
op|':'
newline|'\n'
indent|'    '
name|'pass'
newline|'\n'
dedent|''
endmarker|''
end_unit