def test_base_snap_config_invalid_ep_type(self, mock_os, mock_utils,
                                           mock_renderer):
     '''Ensure endpoint types are correctly validated'''
     self.mock_snap_utils(mock_utils)
     snap = base.OpenStackSnap(os.path.join(TEST_DIR,
                                            'snap-openstack.yaml'))
     mock_os.path.exists.side_effect = self.mock_exists
     self.assertRaises(ValueError, snap.execute,
                       ['snap-openstack', 'keystone-broken'])
 def test_base_snap_config_missing_entry_point(self, mock_os, mock_utils,
                                               mock_renderer):
     '''Ensure ValueError raised for missing entry_point'''
     self.mock_snap_utils(mock_utils)
     snap = base.OpenStackSnap(os.path.join(TEST_DIR,
                                            'snap-openstack.yaml'))
     mock_os.path.exists.side_effect = self.mock_exists
     self.assertRaises(ValueError, snap.execute,
                       ['snap-openstack', 'keystone-api'])
 def test_base_snap_config_nginx(self, mock_os, mock_utils, mock_renderer):
     '''Ensure wrapped binary of nginx called with correct arguments'''
     self.mock_snap_utils(mock_utils)
     snap = base.OpenStackSnap(os.path.join(TEST_DIR,
                                            'snap-openstack.yaml'))
     mock_os.path.exists.side_effect = self.mock_exists
     snap.execute(['snap-openstack', 'keystone-nginx'])
     mock_os.execvp.assert_called_with(
         '/snap/keystone/current/usr/sbin/nginx', [
             '/snap/keystone/current/usr/sbin/nginx', '-g',
             'daemon on; master_process on;', '-c',
             '/var/snap/keystone/common/etc/nginx/snap/nginx.conf'
         ])
 def test_base_snap_config(self, mock_os, mock_utils, mock_renderer):
     '''Ensure wrapped binary called with full args list'''
     self.mock_snap_utils(mock_utils)
     snap = base.OpenStackSnap(os.path.join(TEST_DIR,
                                            'snap-openstack.yaml'))
     mock_os.path.exists.side_effect = self.mock_exists
     mock_os.path.basename.side_effect = 'keystone.conf'
     snap.execute(['snap-openstack', 'keystone-manage'])
     mock_os.execvp.assert_called_with(
         '/snap/keystone/current/bin/keystone-manage', [
             '/snap/keystone/current/bin/keystone-manage',
             '--config-file=/snap/keystone/current/etc/keystone/keystone.conf',
             '--config-dir=/var/snap/keystone/common/etc/keystone/conf.d'
         ])
 def test_base_snap_config_uwsgi(self, mock_os, mock_utils, mock_renderer):
     '''Ensure wrapped binary of uwsgi called with correct arguments'''
     self.mock_snap_utils(mock_utils)
     snap = base.OpenStackSnap(os.path.join(TEST_DIR,
                                            'snap-openstack.yaml'))
     mock_os.path.exists.side_effect = self.mock_exists
     mock_os.path.basename.side_effect = 'keystone.conf'
     builtin = '__builtin__'
     if sys.version_info > (3, 0):
         builtin = 'builtins'
     with patch('{}.open'.format(builtin), mock_open(), create=True):
         snap.execute(['snap-openstack', 'keystone-uwsgi'])
     mock_os.execvp.assert_called_with('/snap/keystone/current/bin/uwsgi', [
         '/snap/keystone/current/bin/uwsgi', '--master', '--die-on-term',
         '-H', '/snap/keystone/current/usr', '--emperor',
         '/var/snap/keystone/common/etc/uwsgi/snap', '--logto',
         '/var/snap/keystone/common/log/uwsgi.log'
     ])
 def test_base_setup(self, mock_os, mock_lock, mock_utils, mock_renderer):
     '''Ensure setup method handles snap-openstack.yaml keys/values'''
     mock_utils_obj = self.mock_snap_utils(mock_utils)
     snap = base.OpenStackSnap(os.path.join(TEST_DIR,
                                            'snap-openstack.yaml'))
     builtin = '__builtin__'
     if sys.version_info > (3, 0):
         builtin = 'builtins'
     with patch('{}.open'.format(builtin), mock_open(), create=True):
         snap.setup()
     mock_lock.assert_called_once_with(
         'setup.lock',
         external=True,
         lock_path='/var/snap/keystone/x1/snap-openstack')
     mock_utils_obj.chmod.assert_called_with(
         '/var/snap/keystone/common/lib', 0o755)
     mock_utils_obj.chown.assert_called_with(
         '/var/snap/keystone/common/lib', 'root', 'root')
     expected = [
         call('/var/snap/keystone/common/etc/keystone/keystone.conf.d',
              perms=488),
         call('/var/snap/keystone/common/etc/nginx/sites-enabled',
              perms=488),
         call('/var/snap/keystone/common/etc/nginx/snap/sites-enabled',
              perms=488),
         call('/var/snap/keystone/common/etc/uwsgi/snap', perms=488),
         call(
             '/var/snap/keystone/common/etc/keystone/keystone.conf.d/'
             'keystone-snap.conf',
             is_file=True),
         call(
             '/var/snap/keystone/common/etc/nginx/snap/sites-enabled/'
             'keystone.conf',
             is_file=True),
         call('/var/snap/keystone/common/etc/nginx/snap/nginx.conf',
              is_file=True)
     ]
     mock_utils_obj.ensure_dir.assert_has_calls(expected, any_order=True)