def test_generate_deployment_params(self): # this method is fairly light, so just make sure that it constructs the dict # to send to the AppController correctly options = flexmock(name='options', table='cassandra', keyname='boo', default_min_appservers='1', autoscale=False, group='bazgroup', replication=None, infrastructure='ec2', machine='ami-ABCDEFG', instance_type='m1.large', use_spot_instances=True, max_spot_price=1.23, clear_datastore=False, disks={'node-1': 'vol-ABCDEFG'}, zone='my-zone-1b', verbose=True, user_commands=[], flower_password="******", default_max_appserver_memory=ParseArgs. DEFAULT_MAX_APPSERVER_MEMORY, EC2_ACCESS_KEY='baz', EC2_SECRET_KEY='baz', EC2_URL='') node_layout = NodeLayout({ 'table': 'cassandra', 'infrastructure': "ec2", 'min_machines': 1, 'max_machines': 1, 'instance_type': 'm1.large' }) flexmock(NodeLayout).should_receive("head_node").and_return( Node('public1', 'some cloud', ['some role'])) expected = { 'table': 'cassandra', 'login': '******', 'clear_datastore': 'False', 'keyname': 'boo', 'default_min_appservers': '1', 'autoscale': 'False', 'replication': 'None', 'group': 'bazgroup', 'machine': 'ami-ABCDEFG', 'infrastructure': 'ec2', 'instance_type': 'm1.large', 'min_machines': '1', 'max_machines': '1', 'use_spot_instances': 'True', 'user_commands': json.dumps([]), 'max_spot_price': '1.23', 'zone': 'my-zone-1b', 'verbose': 'True', 'flower_password': '******', 'default_max_appserver_memory': str(ParseArgs.DEFAULT_MAX_APPSERVER_MEMORY), 'EC2_ACCESS_KEY': 'baz', 'EC2_SECRET_KEY': 'baz', 'EC2_URL': '' } actual = LocalState.generate_deployment_params( options, node_layout, {'max_spot_price': '1.23'}) self.assertEquals(expected, actual)
def test_start_head_node(self): self.options = flexmock(infrastructure='public cloud', group='group', machine='vm image', instance_type='instance type', keyname='keyname', table='cassandra', verbose=False, test=False, use_spot_instances=False, zone='zone', static_ip=None, replication=None, appengine=None, autoscale=None, user_commands=[], flower_password='', max_memory='X', ips=ONE_NODE_CLOUD) self.node_layout = NodeLayout(self.options) flexmock(LocalState).\ should_receive("generate_secret_key").\ with_args(self.options.keyname).\ and_return('some secret key') flexmock(LocalState).\ should_receive("get_key_path_from_name").\ with_args(self.options.keyname).\ and_return('some key path') flexmock(NodeLayout).should_receive('head_node').\ and_return(Node('some IP', 'cloud')) fake_agent = FakeAgent() flexmock(factory.InfrastructureAgentFactory).\ should_receive('create_agent').\ with_args('public cloud').\ and_return(fake_agent) self.additional_params = {} deployment_params = {} flexmock(LocalState).\ should_receive('generate_deployment_params').\ with_args(self.options, self.node_layout, self.additional_params).\ and_return(deployment_params) flexmock(AppScaleLogger).should_receive('log').and_return() flexmock(AppScaleLogger).should_receive('remote_log_tools_state').\ and_return() flexmock(time).should_receive('sleep').and_return() flexmock(RemoteHelper).\ should_receive('copy_deployment_credentials').\ with_args('some IP', self.options).\ and_return() flexmock(RemoteHelper).\ should_receive('run_user_commands').\ with_args('some IP', self.options.user_commands, self.options.keyname, self.options.verbose).\ and_return() flexmock(RemoteHelper).\ should_receive('start_remote_appcontroller').\ with_args('some IP', self.options.keyname, self.options.verbose).\ and_return() layout = {} flexmock(NodeLayout).should_receive('to_list').and_return(layout) flexmock(AppControllerClient).\ should_receive('set_parameters').\ with_args(layout, deployment_params).\ and_return() RemoteHelper.start_head_node(self.options, 'an ID', self.node_layout)