Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
Zach Marano committed Nov 15, 2019
2 parents be2c905 + 9d9a5f9 commit ac1ccb7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from google_compute_engine import logger
from google_compute_engine import metadata_watcher
from google_compute_engine.boto import boto_config
from google_compute_engine.compat import distro_name, urlerror
from google_compute_engine.compat import urlerror
from google_compute_engine.compat import urlrequest
from google_compute_engine.instance_setup import instance_config

Expand Down Expand Up @@ -65,27 +65,17 @@ def __init__(self, debug=False):
instance_config_metadata = self._GetInstanceConfig()
self.instance_config = instance_config.InstanceConfig(
logger=self.logger, instance_config_metadata=instance_config_metadata)

if self.instance_config.GetOptionBool('InstanceSetup', 'set_host_keys'):
host_key_types = self.instance_config.GetOptionString(
'InstanceSetup', 'host_key_types')
self._SetSshHostKeys(host_key_types=host_key_types)

if self.instance_config.GetOptionBool('InstanceSetup', 'set_boto_config'):
self._SetupBotoConfig()

# machineType is e.g. u'projects/00000000000000/machineTypes/n1-standard-1'
machineType = self.metadata_dict['instance']['machineType'].split('/')[-1]
if machineType.startswith("e2-") and 'bsd' not in distro_name: # Not yet supported on BSD.
subprocess.call(["sysctl", "vm.overcommit_memory=1"])

if self.instance_config.GetOptionBool(
'InstanceSetup', 'optimize_local_ssd'):
self._RunScript('google_optimize_local_ssd')

if self.instance_config.GetOptionBool('InstanceSetup', 'set_multiqueue'):
self._RunScript('google_set_multiqueue')

try:
self.instance_config.WriteConfig()
except (IOError, OSError) as e:
Expand Down Expand Up @@ -215,9 +205,10 @@ def _SetSshHostKeys(self, host_key_types=None):
Args:
host_key_types: string, a comma separated list of host key types.
"""
section = 'Instance'
instance_id = self._GetInstanceId()
if instance_id != self.instance_config.GetOptionString(
'instance', 'instance_id'):
section, 'instance_id'):
self.logger.info('Generating SSH host keys for instance %s.', instance_id)
file_regex = re.compile(r'ssh_host_(?P<type>[a-z0-9]*)_key\Z')
key_dir = '/etc/ssh'
Expand All @@ -231,7 +222,7 @@ def _SetSshHostKeys(self, host_key_types=None):
if key_data:
self._WriteHostKeyToGuestAttributes(key_data[0], key_data[1])
self._StartSshd()
self.instance_config.SetOption('Instance', 'instance_id', str(instance_id))
self.instance_config.SetOption(section, 'instance_id', str(instance_id))

def _GetNumericProjectId(self):
"""Get the numeric project ID.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def testInstanceSetup(self, mock_logger, mock_watcher, mock_config):
mock_logger_instance = mock.Mock()
mock_logger.Logger.return_value = mock_logger_instance
mock_watcher_instance = mock.Mock()
mock_watcher_instance.GetMetadata.return_value = {'hello': 'world', 'instance': {'machineType': 'fake'}}
mock_watcher_instance.GetMetadata.return_value = {'hello': 'world'}
mock_watcher.MetadataWatcher.return_value = mock_watcher_instance
mock_config_instance = mock.Mock()
mock_config_instance.GetOptionBool.return_value = True
Expand Down Expand Up @@ -91,7 +91,7 @@ def testInstanceSetup(self, mock_logger, mock_watcher, mock_config):
mock.call.config.InstanceConfig().WriteConfig(),
]
self.assertEqual(mocks.mock_calls, expected_calls)
self.assertEqual(mock_setup.metadata_dict, {'hello': 'world', 'instance': {'machineType': 'fake'}})
self.assertEqual(mock_setup.metadata_dict, {'hello': 'world'})

@mock.patch('google_compute_engine.instance_setup.instance_setup.instance_config')
@mock.patch('google_compute_engine.instance_setup.instance_setup.metadata_watcher')
Expand Down Expand Up @@ -386,7 +386,7 @@ def testSetSshHostKeysFirstBoot(self, mock_listdir):
]

self.assertEqual(sorted(mock_generate_key.mock_calls), expected_calls)
self.mock_instance_config.SetOption.assert_called_with(
self.mock_instance_config.SetOption.assert_called_once_with(
'Instance', 'instance_id', '123')

def testGetNumericProjectId(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
python-google-compute-engine (1:20191115.00-g1) stable; urgency=medium

* REVERT: Enable sysctl change for E2 platform.

-- Google Cloud Team <gc-team@google.com> Fri, 15 Sep 2019 10:08:24 -0700

python-google-compute-engine (1:20191112.00-g1) stable; urgency=medium

* Enable sysctl change for E2 platform.
* Retry metadata lookups in agent.
* Wait for link-local IPv6 addresses to resolve.

-- Google Cloud Team <gc-team@google.com> Mon, 16 Sep 2019 15:52:24 -0700
-- Google Cloud Team <gc-team@google.com> Mon, 11 Nov 2019 15:52:24 -0700

python-google-compute-engine (1:20190916.00-g1) stable; urgency=medium

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.

NAME="python-google-compute-engine"
VERSION="20191112.00"
VERSION="20191115.00"

working_dir=${PWD}
if [[ $(basename "$working_dir") != $NAME ]]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.

NAME="python-google-compute-engine"
VERSION="20191112.00"
VERSION="20191115.00"

rpm_working_dir=/tmp/rpmpackage/${NAME}-${VERSION}
working_dir=${PWD}
Expand Down

0 comments on commit ac1ccb7

Please sign in to comment.