|
1806 | 1806 | }.to change { VCAP::CloudController::RevisionModel.count }.by(1) |
1807 | 1807 | end |
1808 | 1808 | end |
| 1809 | + |
| 1810 | + context 'when app lifecycle is kpack' do |
| 1811 | + let(:app_model) { VCAP::CloudController::AppModel.make(:kpack, name: 'app-name', droplet: VCAP::CloudController::DropletModel.make(:kpack), space: space) } |
| 1812 | + |
| 1813 | + before do |
| 1814 | + VCAP::CloudController::FeatureFlag.make(name: 'diego_docker', enabled: false, error_message: nil) |
| 1815 | + end |
| 1816 | + |
| 1817 | + it 'starts the app' do |
| 1818 | + post "/v3/apps/#{app_model.guid}/actions/start", nil, user_header |
| 1819 | + expect(last_response.status).to eq(200) |
| 1820 | + |
| 1821 | + parsed_response = MultiJson.load(last_response.body) |
| 1822 | + expect(parsed_response).to be_a_response_like({ |
| 1823 | + 'name' => 'app-name', |
| 1824 | + 'guid' => app_model.guid, |
| 1825 | + 'state' => 'STARTED', |
| 1826 | + 'created_at' => iso8601, |
| 1827 | + 'updated_at' => iso8601, |
| 1828 | + 'metadata' => { 'labels' => {}, 'annotations' => {} }, |
| 1829 | + 'lifecycle' => { |
| 1830 | + 'type' => 'kpack', |
| 1831 | + 'data' => {} |
| 1832 | + }, |
| 1833 | + 'relationships' => { |
| 1834 | + 'space' => { |
| 1835 | + 'data' => { |
| 1836 | + 'guid' => space.guid |
| 1837 | + } |
| 1838 | + } |
| 1839 | + }, |
| 1840 | + 'links' => { |
| 1841 | + 'self' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}" }, |
| 1842 | + 'processes' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/processes" }, |
| 1843 | + 'packages' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/packages" }, |
| 1844 | + 'environment_variables' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/environment_variables" }, |
| 1845 | + 'space' => { 'href' => "#{link_prefix}/v3/spaces/#{space.guid}" }, |
| 1846 | + 'current_droplet' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/droplets/current" }, |
| 1847 | + 'droplets' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/droplets" }, |
| 1848 | + 'tasks' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/tasks" }, |
| 1849 | + 'start' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/actions/start", 'method' => 'POST' }, |
| 1850 | + 'stop' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/actions/stop", 'method' => 'POST' }, |
| 1851 | + 'revisions' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/revisions" }, |
| 1852 | + 'deployed_revisions' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/revisions/deployed" }, |
| 1853 | + 'features' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/features" }, |
| 1854 | + } |
| 1855 | + }) |
| 1856 | + |
| 1857 | + event = VCAP::CloudController::Event.last |
| 1858 | + expect(event.values).to include({ |
| 1859 | + type: 'audit.app.start', |
| 1860 | + actee: app_model.guid, |
| 1861 | + actee_type: 'app', |
| 1862 | + actee_name: 'app-name', |
| 1863 | + actor: user.guid, |
| 1864 | + actor_type: 'user', |
| 1865 | + actor_name: user_email, |
| 1866 | + actor_username: user_name, |
| 1867 | + space_guid: space.guid, |
| 1868 | + organization_guid: space.organization.guid, |
| 1869 | + }) |
| 1870 | + end |
| 1871 | + end |
1809 | 1872 | end |
1810 | 1873 |
|
1811 | 1874 | describe 'POST /v3/apps/:guid/actions/stop' do |
|
1921 | 1984 | desired_state: 'STARTED', |
1922 | 1985 | ) |
1923 | 1986 | } |
1924 | | - let!(:droplet) do |
1925 | | - VCAP::CloudController::DropletModel.make( |
1926 | | - :buildpack, |
1927 | | - app: app_model, |
1928 | | - state: VCAP::CloudController::DropletModel::STAGED_STATE |
1929 | | - ) |
1930 | | - end |
1931 | | - before do |
1932 | | - app_model.lifecycle_data.buildpacks = ['http://example.com/git'] |
1933 | | - app_model.lifecycle_data.stack = stack.name |
1934 | | - app_model.lifecycle_data.save |
1935 | | - app_model.droplet = droplet |
1936 | | - app_model.save |
| 1987 | + |
| 1988 | + context 'app lifecycle is buildpack' do |
| 1989 | + let!(:droplet) do |
| 1990 | + VCAP::CloudController::DropletModel.make( |
| 1991 | + :buildpack, |
| 1992 | + app: app_model, |
| 1993 | + state: VCAP::CloudController::DropletModel::STAGED_STATE |
| 1994 | + ) |
| 1995 | + end |
| 1996 | + |
| 1997 | + before do |
| 1998 | + app_model.lifecycle_data.buildpacks = ['http://example.com/git'] |
| 1999 | + app_model.lifecycle_data.stack = stack.name |
| 2000 | + app_model.lifecycle_data.save |
| 2001 | + app_model.droplet = droplet |
| 2002 | + app_model.save |
| 2003 | + end |
| 2004 | + |
| 2005 | + it 'restarts the app' do |
| 2006 | + post "/v3/apps/#{app_model.guid}/actions/restart", nil, user_header |
| 2007 | + expect(last_response.status).to eq(200) |
| 2008 | + |
| 2009 | + parsed_response = MultiJson.load(last_response.body) |
| 2010 | + expect(parsed_response).to be_a_response_like( |
| 2011 | + { |
| 2012 | + 'name' => 'app-name', |
| 2013 | + 'guid' => app_model.guid, |
| 2014 | + 'state' => 'STARTED', |
| 2015 | + 'created_at' => iso8601, |
| 2016 | + 'updated_at' => iso8601, |
| 2017 | + 'metadata' => { 'labels' => {}, 'annotations' => {} }, |
| 2018 | + 'lifecycle' => { |
| 2019 | + 'type' => 'buildpack', |
| 2020 | + 'data' => { |
| 2021 | + 'buildpacks' => ['http://example.com/git'], |
| 2022 | + 'stack' => 'stack-name', |
| 2023 | + } |
| 2024 | + }, |
| 2025 | + 'relationships' => { |
| 2026 | + 'space' => { |
| 2027 | + 'data' => { |
| 2028 | + 'guid' => space.guid |
| 2029 | + } |
| 2030 | + } |
| 2031 | + }, |
| 2032 | + 'links' => { |
| 2033 | + 'self' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}" }, |
| 2034 | + 'processes' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/processes" }, |
| 2035 | + 'packages' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/packages" }, |
| 2036 | + 'environment_variables' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/environment_variables" }, |
| 2037 | + 'space' => { 'href' => "#{link_prefix}/v3/spaces/#{space.guid}" }, |
| 2038 | + 'current_droplet' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/droplets/current" }, |
| 2039 | + 'droplets' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/droplets" }, |
| 2040 | + 'tasks' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/tasks" }, |
| 2041 | + 'start' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/actions/start", 'method' => 'POST' }, |
| 2042 | + 'stop' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/actions/stop", 'method' => 'POST' }, |
| 2043 | + 'revisions' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/revisions" }, |
| 2044 | + 'deployed_revisions' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/revisions/deployed" }, |
| 2045 | + 'features' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/features" }, |
| 2046 | + } |
| 2047 | + } |
| 2048 | + ) |
| 2049 | + end |
| 2050 | + context 'telemetry' do |
| 2051 | + it 'should log the required fields when the app is restarted' do |
| 2052 | + Timecop.freeze do |
| 2053 | + expected_json = { |
| 2054 | + 'telemetry-source' => 'cloud_controller_ng', |
| 2055 | + 'telemetry-time' => Time.now.to_datetime.rfc3339, |
| 2056 | + 'restart-app' => { |
| 2057 | + 'api-version' => 'v3', |
| 2058 | + 'app-id' => Digest::SHA256.hexdigest(app_model.guid), |
| 2059 | + 'user-id' => Digest::SHA256.hexdigest(user.guid), |
| 2060 | + } |
| 2061 | + } |
| 2062 | + expect_any_instance_of(ActiveSupport::Logger).to receive(:info).with(JSON.generate(expected_json)) |
| 2063 | + |
| 2064 | + post "/v3/apps/#{app_model.guid}/actions/restart", nil, user_header |
| 2065 | + |
| 2066 | + expect(last_response.status).to eq(200), last_response.body |
| 2067 | + end |
| 2068 | + end |
| 2069 | + end |
1937 | 2070 | end |
1938 | 2071 |
|
1939 | | - it 'restarts the app' do |
1940 | | - post "/v3/apps/#{app_model.guid}/actions/restart", nil, user_header |
1941 | | - expect(last_response.status).to eq(200) |
| 2072 | + context 'app lifecycle is kpack' do |
| 2073 | + let(:app_model) { |
| 2074 | + VCAP::CloudController::AppModel.make(:kpack, |
| 2075 | + name: 'app-name', |
| 2076 | + droplet: VCAP::CloudController::DropletModel.make(:kpack), |
| 2077 | + space: space, |
| 2078 | + desired_state: 'STARTED') |
| 2079 | + } |
1942 | 2080 |
|
1943 | | - parsed_response = MultiJson.load(last_response.body) |
1944 | | - expect(parsed_response).to be_a_response_like( |
1945 | | - { |
| 2081 | + before do |
| 2082 | + VCAP::CloudController::FeatureFlag.make(name: 'diego_docker', enabled: false, error_message: nil) |
| 2083 | + end |
| 2084 | + |
| 2085 | + it 'restarts the app' do |
| 2086 | + post "/v3/apps/#{app_model.guid}/actions/restart", nil, user_header |
| 2087 | + expect(last_response.status).to eq(200) |
| 2088 | + |
| 2089 | + parsed_response = MultiJson.load(last_response.body) |
| 2090 | + expect(parsed_response).to be_a_response_like( |
| 2091 | + { |
1946 | 2092 | 'name' => 'app-name', |
1947 | 2093 | 'guid' => app_model.guid, |
1948 | 2094 | 'state' => 'STARTED', |
1949 | 2095 | 'created_at' => iso8601, |
1950 | 2096 | 'updated_at' => iso8601, |
1951 | 2097 | 'metadata' => { 'labels' => {}, 'annotations' => {} }, |
1952 | 2098 | 'lifecycle' => { |
1953 | | - 'type' => 'buildpack', |
1954 | | - 'data' => { |
1955 | | - 'buildpacks' => ['http://example.com/git'], |
1956 | | - 'stack' => 'stack-name', |
1957 | | - } |
| 2099 | + 'type' => 'kpack', |
| 2100 | + 'data' => {} |
1958 | 2101 | }, |
1959 | 2102 | 'relationships' => { |
1960 | | - 'space' => { |
1961 | | - 'data' => { |
1962 | | - 'guid' => space.guid |
1963 | | - } |
| 2103 | + 'space' => { |
| 2104 | + 'data' => { |
| 2105 | + 'guid' => space.guid |
1964 | 2106 | } |
| 2107 | + } |
1965 | 2108 | }, |
1966 | 2109 | 'links' => { |
1967 | | - 'self' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}" }, |
1968 | | - 'processes' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/processes" }, |
1969 | | - 'packages' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/packages" }, |
1970 | | - 'environment_variables' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/environment_variables" }, |
1971 | | - 'space' => { 'href' => "#{link_prefix}/v3/spaces/#{space.guid}" }, |
1972 | | - 'current_droplet' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/droplets/current" }, |
1973 | | - 'droplets' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/droplets" }, |
1974 | | - 'tasks' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/tasks" }, |
1975 | | - 'start' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/actions/start", 'method' => 'POST' }, |
1976 | | - 'stop' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/actions/stop", 'method' => 'POST' }, |
1977 | | - 'revisions' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/revisions" }, |
1978 | | - 'deployed_revisions' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/revisions/deployed" }, |
1979 | | - 'features' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/features" }, |
1980 | | - } |
1981 | | - } |
1982 | | - ) |
1983 | | - end |
1984 | | - context 'telemetry' do |
1985 | | - it 'should log the required fields when the app is restarted' do |
1986 | | - Timecop.freeze do |
1987 | | - expected_json = { |
1988 | | - 'telemetry-source' => 'cloud_controller_ng', |
1989 | | - 'telemetry-time' => Time.now.to_datetime.rfc3339, |
1990 | | - 'restart-app' => { |
1991 | | - 'api-version' => 'v3', |
1992 | | - 'app-id' => Digest::SHA256.hexdigest(app_model.guid), |
1993 | | - 'user-id' => Digest::SHA256.hexdigest(user.guid), |
| 2110 | + 'self' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}" }, |
| 2111 | + 'processes' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/processes" }, |
| 2112 | + 'packages' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/packages" }, |
| 2113 | + 'environment_variables' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/environment_variables" }, |
| 2114 | + 'space' => { 'href' => "#{link_prefix}/v3/spaces/#{space.guid}" }, |
| 2115 | + 'current_droplet' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/droplets/current" }, |
| 2116 | + 'droplets' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/droplets" }, |
| 2117 | + 'tasks' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/tasks" }, |
| 2118 | + 'start' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/actions/start", 'method' => 'POST' }, |
| 2119 | + 'stop' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/actions/stop", 'method' => 'POST' }, |
| 2120 | + 'revisions' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/revisions" }, |
| 2121 | + 'deployed_revisions' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/revisions/deployed" }, |
| 2122 | + 'features' => { 'href' => "#{link_prefix}/v3/apps/#{app_model.guid}/features" }, |
1994 | 2123 | } |
1995 | 2124 | } |
1996 | | - expect_any_instance_of(ActiveSupport::Logger).to receive(:info).with(JSON.generate(expected_json)) |
1997 | | - |
1998 | | - post "/v3/apps/#{app_model.guid}/actions/restart", nil, user_header |
1999 | | - |
2000 | | - expect(last_response.status).to eq(200), last_response.body |
2001 | | - end |
| 2125 | + ) |
2002 | 2126 | end |
2003 | 2127 | end |
2004 | 2128 | end |
|
0 commit comments