示例#1
0
 def test_add_network(self):
     """
     Test add_network action
     """
     network = {'name': 'network', 'type': 'default', 'id': 'id'}
     gw = Gateway('gw', data=self.valid_data)
     gw.state.set('actions', 'start', 'ok')
     gw.add_network(network)
     assert gw.data['networks'] == [network]
     gw._gateway_sal.deploy.assert_called_once_with()
示例#2
0
 def test_add_network_before_start(self):
     """
     Test add_network action if gateway isn't started
     """
     with pytest.raises(
             StateCheckError,
             message=
             'action should raise an error if another network with the same type and id combination exists'
     ):
         network = {'name': 'network', 'type': 'default', 'id': 'id'}
         gw = Gateway('gw', data=self.valid_data)
         gw.add_network(network)
示例#3
0
 def test_add_network_name_exist_same_combination(self):
     """
     Test add_network action if network with the same type and id combination exists
     """
     with pytest.raises(
             ValueError,
             message=
             'action should raise an error if another network with the same type and id combination exists'
     ):
         network = {'name': 'network', 'type': 'default', 'id': 'id'}
         network_two = {'name': 'network2', 'type': 'default', 'id': 'id'}
         self.valid_data['networks'].append(network)
         gw = Gateway('gw', data=self.valid_data)
         gw.state.set('actions', 'start', 'ok')
         gw.add_network(network_two)
示例#4
0
 def test_add_network_exception(self):
     """
     Test add_network action raises exception
     """
     with pytest.raises(
             RuntimeError,
             message=
             'actions should raise an error deploy raises an exception'):
         network = {'name': 'network', 'type': 'default', 'id': 'id'}
         gw = Gateway('gw', data=self.valid_data)
         gw.state.set('actions', 'start', 'ok')
         gw._gateway_sal.deploy.side_effect = RuntimeError
         gw.add_network(network)
         assert gw.data['networks'] == []
         assert gw._gateway_sal.deploy.call_count == 2