mongoid 7.2.0 → 7.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/lib/mongoid/criteria/queryable/selector.rb +0 -4
  5. data/lib/mongoid/document.rb +3 -2
  6. data/lib/mongoid/interceptable.rb +3 -1
  7. data/lib/mongoid/matcher/field_operator.rb +7 -11
  8. data/lib/mongoid/version.rb +1 -1
  9. data/spec/integration/app_spec.rb +35 -2
  10. data/spec/integration/callbacks_models.rb +49 -0
  11. data/spec/integration/callbacks_spec.rb +216 -0
  12. data/spec/integration/matcher_operator_data/gt_types.yml +63 -0
  13. data/spec/integration/matcher_operator_data/gte_types.yml +15 -0
  14. data/spec/integration/matcher_operator_data/lt_types.yml +15 -0
  15. data/spec/integration/matcher_operator_data/lte_types.yml +15 -0
  16. data/spec/integration/matcher_operator_data/ne_types.yml +15 -0
  17. data/spec/lite_spec_helper.rb +1 -1
  18. data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +50 -0
  19. data/spec/mongoid/atomic/paths_spec.rb +41 -0
  20. data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +36 -0
  21. data/spec/shared/lib/mrss/cluster_config.rb +211 -0
  22. data/spec/shared/lib/mrss/constraints.rb +27 -0
  23. data/spec/shared/lib/mrss/docker_runner.rb +262 -0
  24. data/spec/shared/lib/mrss/server_version_registry.rb +69 -0
  25. data/spec/shared/share/Dockerfile.erb +229 -0
  26. data/spec/shared/shlib/distro.sh +73 -0
  27. data/spec/shared/shlib/server.sh +270 -0
  28. data/spec/shared/shlib/set_env.sh +128 -0
  29. data/spec/support/models/customer.rb +11 -0
  30. data/spec/support/models/customer_address.rb +12 -0
  31. data/spec/support/models/dictionary.rb +6 -0
  32. metadata +44 -12
  33. metadata.gz.sig +0 -0
@@ -0,0 +1,262 @@
1
+ require 'optparse'
2
+ require 'erb'
3
+ autoload :Dotenv, 'dotenv'
4
+
5
+ module Mrss
6
+ autoload :ServerVersionRegistry, 'mrss/server_version_registry'
7
+
8
+ class DockerRunner
9
+ def initialize(**opts)
10
+ # These options are required:
11
+ opts.fetch(:image_tag)
12
+ opts.fetch(:dockerfile_path)
13
+ opts.fetch(:default_script)
14
+ opts.fetch(:project_lib_subdir)
15
+
16
+ @options = opts
17
+ end
18
+
19
+ attr_reader :options
20
+
21
+ def run
22
+ process_arguments
23
+ unless @options[:exec_only]
24
+ create_dockerfile
25
+ create_image
26
+ end
27
+ if @options[:mongo_only]
28
+ run_deployment
29
+ else
30
+ run_tests
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def process_arguments
37
+ #@options = {}
38
+ OptionParser.new do |opts|
39
+ opts.banner = "Usage: test-on-docker [-d distro] [evergreen_key=value ...]"
40
+
41
+ opts.on("-a", "--add-env=PATH", "Load environment variables from PATH in .env format") do |path|
42
+ @options[:extra_env] ||= {}
43
+ unless File.exist?(path)
44
+ raise "-a option references nonexistent file #{path}"
45
+ end
46
+ Dotenv.parse(path).each do |k, v|
47
+ @options[:extra_env][k] = v
48
+ end
49
+ end
50
+
51
+ opts.on("-d", "--distro=DISTRO", "Distro to use") do |v|
52
+ @options[:distro] = v
53
+ end
54
+
55
+ opts.on('-e', '--exec-only', 'Execute tests using existing Dockerfile (for offline user)') do |v|
56
+ @options[:exec_only] = v
57
+ end
58
+
59
+ opts.on('-m', '--mongo-only=PORT', 'Start the MongoDB deployment and expose it to host on ports starting with PORT') do |v|
60
+ @options[:mongo_only] = v.to_i
61
+ end
62
+
63
+ opts.on('-p', '--preload', 'Preload Ruby toolchain and server binaries in docker') do |v|
64
+ @options[:preload] = v
65
+ end
66
+
67
+ opts.on('-s', '--script=SCRIPT', 'Test script to invoke') do |v|
68
+ @options[:script] = v
69
+ end
70
+
71
+ opts.on('-i', '--interactive', 'Interactive mode - disable per-test timeouts') do |v|
72
+ @options[:interactive] = v
73
+ end
74
+ end.parse!
75
+
76
+ @env = Hash[ARGV.map do |arg|
77
+ arg.split('=', 2)
78
+ end]
79
+
80
+ @env['RVM_RUBY'] ||= 'ruby-2.7'
81
+ unless ruby =~ /^j?ruby-/
82
+ raise "RVM_RUBY option is not in expected format: #{ruby}"
83
+ end
84
+
85
+ @env['MONGODB_VERSION'] ||= '4.4'
86
+ end
87
+
88
+ def create_dockerfile
89
+ template_path = File.join(File.dirname(__FILE__), '../../share/Dockerfile.erb')
90
+ result = ERB.new(File.read(template_path)).result(binding)
91
+ File.open(dockerfile_path, 'w') do |f|
92
+ f << result
93
+ end
94
+ end
95
+
96
+ def image_tag
97
+ options.fetch(:image_tag)
98
+ end
99
+
100
+ def dockerfile_path
101
+ options.fetch(:dockerfile_path)
102
+ end
103
+
104
+ def create_image
105
+ run_command(['docker', 'build',
106
+ '-t', image_tag,
107
+ '-f', dockerfile_path,
108
+ '.'])
109
+ end
110
+
111
+ BASE_TEST_COMMAND = %w(docker run -i --tmpfs /tmpfs:exec).freeze
112
+
113
+ def run_tests
114
+ run_command(BASE_TEST_COMMAND + tty_arg + extra_env + [image_tag] +
115
+ script.split(/\s+/))
116
+ end
117
+
118
+ def run_deployment
119
+ run_command(BASE_TEST_COMMAND + tty_arg + extra_env + [
120
+ '-e', %q`TEST_CMD=watch -x bash -c "ps awwxu |egrep 'mongo|ocsp'"`,
121
+ '-e', 'BIND_ALL=true',
122
+ ] + port_forwards + [image_tag] + script.split(/\s+/))
123
+ end
124
+
125
+ def tty_arg
126
+ tty = File.open('/dev/stdin') do |f|
127
+ f.isatty
128
+ end
129
+ if tty
130
+ %w(-t --init)
131
+ else
132
+ []
133
+ end
134
+ end
135
+
136
+ def extra_env
137
+ if @options[:extra_env]
138
+ @options[:extra_env].map do |k, v|
139
+ # Here the value must not be escaped
140
+ ['-e', "#{k}=#{v}"]
141
+ end.flatten
142
+ else
143
+ []
144
+ end
145
+ end
146
+
147
+ def port_forwards
148
+ args = (0...num_exposed_ports).map do |i|
149
+ host_port = @options[:mongo_only] + i
150
+ container_port = 27017 + i
151
+ ['-p', "#{host_port}:#{container_port}"]
152
+ end.flatten
153
+
154
+ if @env['OCSP_ALGORITHM'] && !@env['OCSP_VERIFIER']
155
+ args += %w(-p 8100:8100)
156
+ end
157
+
158
+ args
159
+ end
160
+
161
+ def run_command(cmd)
162
+ if pid = fork
163
+ Process.wait(pid)
164
+ unless $?.exitstatus == 0
165
+ raise "Process exited with code #{$?.exitstatus}"
166
+ end
167
+ else
168
+ exec(*cmd)
169
+ end
170
+ end
171
+
172
+ def distro
173
+ @options[:distro] || 'ubuntu1604'
174
+ end
175
+
176
+ BASE_IMAGES = {
177
+ 'debian81' => 'debian:jessie',
178
+ 'debian92' => 'debian:stretch',
179
+ 'ubuntu1404' => 'ubuntu:trusty',
180
+ 'ubuntu1604' => 'ubuntu:xenial',
181
+ 'ubuntu1804' => 'ubuntu:bionic',
182
+ 'rhel62' => 'centos:6',
183
+ 'rhel70' => 'centos:7',
184
+ }.freeze
185
+
186
+ def base_image
187
+ BASE_IMAGES[distro] or raise "Unknown distro: #{distro}"
188
+ end
189
+
190
+ def ruby
191
+ @env['RVM_RUBY']
192
+ end
193
+
194
+ def ruby_head?
195
+ ruby == 'ruby-head'
196
+ end
197
+
198
+ def server_version
199
+ @env['MONGODB_VERSION']
200
+ end
201
+
202
+ def script
203
+ @options[:script] || options.fetch(:default_script)
204
+ end
205
+
206
+ def debian?
207
+ distro =~ /debian|ubuntu/
208
+ end
209
+
210
+ def preload?
211
+ !!@options[:preload]
212
+ end
213
+
214
+ def interactive?
215
+ !!@options[:interactive]
216
+ end
217
+
218
+ def project_lib_subdir
219
+ options.fetch(:project_lib_subdir)
220
+ end
221
+
222
+ def server_download_url
223
+ @server_download_url ||= ServerVersionRegistry.new(server_version, distro).download_url
224
+ end
225
+
226
+ def libmongocrypt_path
227
+ case distro
228
+ when /ubuntu1604/
229
+ "./ubuntu1604/nocrypto/lib64/libmongocrypt.so"
230
+ when /ubuntu1804/
231
+ "./ubuntu1804-64/nocrypto/lib64/libmongocrypt.so"
232
+ when /debian92/
233
+ "./debian92/nocrypto/lib64/libmongocrypt.so"
234
+ else
235
+ raise "This script does not support running FLE tests on #{distro}. Use ubuntu1604, ubuntu1804 or debian92 instead"
236
+ end
237
+ end
238
+
239
+ def expose?
240
+ !!@options[:mongo_only]
241
+ end
242
+
243
+ def fle?
244
+ %w(1 true yes).include?(@env['FLE']&.downcase)
245
+ end
246
+
247
+ def num_exposed_ports
248
+ case @env['TOPOLOGY'] || 'standalone'
249
+ when 'standalone'
250
+ 1
251
+ when 'replica-set'
252
+ 3
253
+ when 'sharded-cluster'
254
+ if @env['SINGLE_MONGOS']
255
+ 1
256
+ else
257
+ 2
258
+ end
259
+ end
260
+ end
261
+ end
262
+ end
@@ -0,0 +1,69 @@
1
+ autoload :JSON, 'json'
2
+ require 'open-uri'
3
+
4
+ module Mrss
5
+ class ServerVersionRegistry
6
+ def initialize(desired_version, arch)
7
+ @desired_version, @arch = desired_version, arch
8
+ end
9
+
10
+ attr_reader :desired_version, :arch
11
+
12
+ def download_url
13
+ @download_url ||= begin
14
+ info = JSON.load(uri_open('http://downloads.mongodb.org/current.json').read)
15
+ version = info['versions'].detect do |version|
16
+ version['version'].start_with?(desired_version) &&
17
+ !version['version'].include?('-') &&
18
+ # Sometimes the download situation is borked and there is a release
19
+ # with no downloads... skip those.
20
+ !version['downloads'].empty?
21
+ end
22
+ # Allow RC releases if there isn't a GA release.
23
+ version ||= info['versions'].detect do |version|
24
+ version['version'].start_with?(desired_version) &&
25
+ # Sometimes the download situation is borked and there is a release
26
+ # with no downloads... skip those.
27
+ !version['downloads'].empty?
28
+ end
29
+ if version.nil?
30
+ info = JSON.load(URI.parse('http://downloads.mongodb.org/full.json').open.read)
31
+ versions = info['versions'].select do |version|
32
+ version['version'].start_with?(desired_version) &&
33
+ !version['downloads'].empty?
34
+ end
35
+ # Get rid of rc, beta etc. versions if there is a GA release.
36
+ if versions.any? { |version| !version.include?('-') }
37
+ versions.delete_if do |version|
38
+ version['version'].include?('-')
39
+ end
40
+ end
41
+ # Versions are ordered with newest first, take the first one i.e. the most
42
+ # recent one.
43
+ version = versions.first
44
+ if version.nil?
45
+ STDERR.puts "Error: no version #{desired_version}"
46
+ exit 2
47
+ end
48
+ end
49
+ dl = version['downloads'].detect do |dl|
50
+ dl['archive']['url'].index("enterprise-#{arch}") &&
51
+ dl['arch'] == 'x86_64'
52
+ end
53
+ unless dl
54
+ STDERR.puts "Error: no download for #{arch} for #{version['version']}"
55
+ exit 2
56
+ end
57
+ url = dl['archive']['url']
58
+ end
59
+ end
60
+
61
+ def uri_open(*args)
62
+ if RUBY_VERSION < '2.5'
63
+ open(*args)
64
+ else
65
+ URI.open(*args)
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,229 @@
1
+ # Python toolchain as of this writing is available on rhel62, debian92 and
2
+ # ubuntu1604.
3
+ #
4
+ # To run rhel62 in docker, host system must be configured to emulate syscalls:
5
+ # https://github.com/CentOS/sig-cloud-instance-images/issues/103
6
+
7
+ <%
8
+
9
+ python_toolchain_url = "https://s3.amazonaws.com//mciuploads/mongo-python-driver-toolchain/#{distro}/ba92de2700c04ee2d4f82c3ffdfc33105140cb04/mongo_python_driver_toolchain_#{distro.gsub('-', '_')}_ba92de2700c04ee2d4f82c3ffdfc33105140cb04_19_11_14_15_33_33.tar.gz"
10
+ server_version = '4.3.3'
11
+ server_url = "http://downloads.10gen.com/linux/mongodb-linux-x86_64-enterprise-#{distro}-#{server_version}.tgz"
12
+ server_archive_basename = File.basename(server_url)
13
+ server_extracted_dir = server_archive_basename.sub(/\.(tar\.gz|tgz)$/, '')
14
+
15
+ toolchain_upper='291ba4a4e8297f142796e70eee71b99f333e35e1'
16
+
17
+ ruby_toolchain_url = "http://boxes.10gen.com/build/toolchain-drivers/mongo-ruby-driver/ruby-toolchain-#{distro}-#{toolchain_upper}.tar.xz"
18
+ #ruby_toolchain_url = "https://s3.amazonaws.com//mciuploads/mongo-ruby-toolchain/#{distro}/#{toolchain_upper}/mongo_ruby_driver_toolchain_#{distro.gsub('-', '_')}_patch_#{toolchain_upper}_#{toolchain_lower}.tar.gz"
19
+
20
+ %>
21
+
22
+ FROM <%= base_image %>
23
+
24
+ <% if debian? %>
25
+
26
+ ENV DEBIAN_FRONTEND=noninteractive
27
+
28
+ <% else %>
29
+
30
+ RUN echo assumeyes=1 |tee -a /etc/yum.conf
31
+
32
+ <% end %>
33
+
34
+ <% if ruby_head? %>
35
+
36
+ # To use current versions of mlaunch, Python 3.6+ is required.
37
+ # Most distros ship with older Pythons, therefore we need to install
38
+ # a newer Python from somewhere. This section installs the Python
39
+ # toolhcain which comes with recent Pythons.
40
+ # Alternatively, Ruby toolchain compiles its own copy of Python 3 but
41
+ # this is currently incomplete in that on older distros with old OpenSSL,
42
+ # the built Python has no ssl module and hence practically is unusable.
43
+ # Currently Ruby driver uses mtools-legacy which supports Python 2,
44
+ # avoiding this entire issue for the time being.
45
+
46
+ #RUN curl --retry 3 -fL <%= python_toolchain_url %> -o python-toolchain.tar.gz
47
+ #RUN tar -xC /opt -zf python-toolchain.tar.gz
48
+
49
+ <% end %>
50
+
51
+ <% if debian? %>
52
+
53
+ # zsh is not required for any scripts but it is a better interactive shell
54
+ # than bash.
55
+ # Ruby runtime dependencies: libyaml-0-2
56
+ # Compiling ruby libraries: gcc make
57
+ # Compiling pyhton packages: python2.7-dev
58
+ # JRuby: openjdk-8-jre-headless
59
+ # Server dependencies: libsnmp30 libcurl3/libcurl4
60
+ # Determining OS we are running on: lsb-release
61
+ # Kerberos testing: krb5-user
62
+ # Local Kerberos server: krb5-kdc krb5-admin-server
63
+ # Installing mlaunch from git: git
64
+ # ruby-head archive: bzip2
65
+ # nio4r on JRuby: libgmp-dev
66
+ # Snappy compression: libsnappy-dev
67
+ # nokogiri: zlib1g-dev
68
+ # Mongoid testing: tzdata
69
+ # Mongoid application testing: nodejs (8.x or newer)
70
+ #
71
+ # We currently use Python 2-compatible version of mtools, which
72
+ # is installable via pip (which uses Python 2). All of the MongoDB
73
+ # distros have pip installed (but none as of this writing have pip3)
74
+ # therefore install python-pip in all configurations here.
75
+
76
+ <% packages = %w(
77
+ lsb-release bzip2 curl zsh
78
+ git make gcc libyaml-0-2 libgmp-dev zlib1g-dev libsnappy-dev
79
+ libsnmp30
80
+ krb5-user krb5-kdc krb5-admin-server libsasl2-dev libsasl2-modules-gssapi-mit
81
+ python-pip python2.7-dev python3-pip
82
+ tzdata
83
+ ) %>
84
+
85
+ # ubuntu1404 only has openjdk-7-jre-headless
86
+ <% if distro !~ /ubuntu1404/ %>
87
+ <% packages << 'openjdk-8-jre-headless' %>
88
+ <% end %>
89
+
90
+ # ubuntu1404, ubuntu1604: libcurl3
91
+ # ubuntu1804: libcurl4
92
+ <% if distro =~ /ubuntu1804/ %>
93
+ <% packages << 'libcurl4' %>
94
+ <% else %>
95
+ <% packages << 'libcurl3' %>
96
+ <% end %>
97
+
98
+ <% if distro =~ /ubuntu1804/ %>
99
+ <% packages << 'nodejs' %>
100
+ <% end %>
101
+
102
+ RUN apt-get update && apt-get install -y <%= packages.join(' ') %>
103
+ <% else %>
104
+
105
+ # Enterprise server: net-snmp
106
+ # lsb_release: redhat-lsb-core
107
+ # our runner scripts: which
108
+ # Ruby dependency: libyaml
109
+ # compiling python packages: gcc python-devel
110
+ # Kerberos tests: krb5-workstation + cyrus-sasl-devel to build the
111
+ # mongo_kerberos gem + cyrus-sasl-gssapi for authentication to work
112
+ # Local Kerberos server: krb5-server
113
+ # JRuby: java-1.8.0-openjdk
114
+ #
115
+ # Note: lacking cyrus-sasl-gssapi produces a cryptic message
116
+ # "SASL(-4): no mechanism available: No worthy mechs found"
117
+ # https://github.com/farorm/python-ad/issues/10
118
+
119
+ RUN yum install -y redhat-lsb-core which git gcc libyaml krb5-server \
120
+ krb5-workstation cyrus-sasl-devel cyrus-sasl-gssapi java-1.8.0-openjdk \
121
+ net-snmp
122
+
123
+ <% if distro =~ /rhel6/ %>
124
+
125
+ # RHEL 6 ships with Python 2.6.
126
+
127
+ RUN yum install -y centos-release-scl && \
128
+ yum install -y python27-python python27-python-devel
129
+ ENV PATH=/opt/rh/python27/root/usr/bin:$PATH \
130
+ LD_LIBRARY_PATH=/opt/rh/python27/root/usr/lib64
131
+
132
+ <% else %>
133
+
134
+ RUN yum install -y python-devel
135
+
136
+ <% end %>
137
+
138
+ <% end %>
139
+
140
+ <% if preload? %>
141
+
142
+ WORKDIR /app
143
+
144
+ RUN curl --retry 3 -fL <%= server_download_url %> |tar xzf - && \
145
+ mv mongo*/ /opt/mongodb
146
+ ENV USE_OPT_MONGODB=1
147
+
148
+ <% unless ruby_head? %>
149
+
150
+ RUN curl --retry 3 -fL <%= ruby_toolchain_url %> |tar -xC /opt -Jf -
151
+ ENV PATH=/opt/rubies/<%= ruby %>/bin:$PATH \
152
+ USE_OPT_TOOLCHAIN=1
153
+ #ENV PATH=/opt/rubies/python/3/bin:$PATH
154
+
155
+ <% end %>
156
+
157
+ <% if distro =~ /rhel|ubuntu1604/ %>
158
+
159
+ # Ubuntu 12.04 ships pip 1.0 which is ancient and does not work.
160
+ #
161
+ # Ubuntu 16.04 apparently also ships a pip that does not work:
162
+ # https://stackoverflow.com/questions/37495375/python-pip-install-throws-typeerror-unsupported-operand-types-for-retry
163
+ # Potentially this only affects environments with less than ideal
164
+ # connectivity (or, perhaps, when python package registry is experiencing
165
+ # availability issues) when pip must retry to install packages.
166
+ #
167
+ # rhel apparently does not package pip at all in core repoitories,
168
+ # therefore install it the manual way.
169
+ #
170
+ # https://pip.pypa.io/en/stable/installing/
171
+ RUN curl --retry 3 -fL https://raw.githubusercontent.com/pypa/get-pip/master/2.7/get-pip.py | python
172
+
173
+ <% end %>
174
+
175
+ RUN pip --version && \
176
+ pip install mtools-legacy[mlaunch]
177
+
178
+ <% if @env.fetch('MONGODB_VERSION') >= '4.4' %>
179
+ RUN python3 -mpip install asn1crypto oscrypto flask
180
+ <% end %>
181
+
182
+ <% end %>
183
+
184
+ WORKDIR /app
185
+
186
+ <% if preload? && !ruby_head? %>
187
+
188
+ COPY Gemfile .
189
+ COPY gemfiles gemfiles
190
+ COPY *.gemspec .
191
+ COPY lib/<%= project_lib_subdir %>/version.rb lib/<%= project_lib_subdir %>/version.rb
192
+ RUN bundle install
193
+ COPY .evergreen/patch-debuggers .evergreen/patch-debuggers
194
+ RUN .evergreen/patch-debuggers /opt/rubies
195
+
196
+ <% end %>
197
+
198
+ <% if fle? %>
199
+ RUN curl --retry 3 -fLo libmongocrypt-all.tar.gz "https://s3.amazonaws.com/mciuploads/libmongocrypt/all/master/latest/libmongocrypt-all.tar.gz"
200
+ RUN tar xf libmongocrypt-all.tar.gz
201
+
202
+ <%= "ENV LIBMONGOCRYPT_PATH #{libmongocrypt_path}" %>
203
+ <% end %>
204
+
205
+ ENV MONGO_ORCHESTRATION_HOME=/tmpfs \
206
+ PROJECT_DIRECTORY=/app \
207
+ <%= @env.map { |k, v| %Q`#{k}="#{v.gsub('$', "\\$").gsub('"', "\\\"")}"` }.join(" \\\n ") %>
208
+
209
+ <% if interactive? %>
210
+ ENV INTERACTIVE=1
211
+ <% end %>
212
+
213
+ COPY . .
214
+
215
+ <% if expose? %>
216
+
217
+ <% ports = [] %>
218
+
219
+ <% 0.upto(num_exposed_ports-1) do |i| %>
220
+ <% ports << 27017 + i %>
221
+ <% end %>
222
+
223
+ <% if @env['OCSP_ALGORITHM'] %>
224
+ <% ports << 8100 %>
225
+ <% end %>
226
+
227
+ EXPOSE <%= ports.map(&:to_s).join(' ') %>
228
+
229
+ <% end %>